Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit 749ef2b

Browse files
committed
initial commit
1 parent 55f3ac1 commit 749ef2b

File tree

193 files changed

+2743
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+2743
-1
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/.bundle/
2+
/.yardoc
3+
/Gemfile.lock
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/
10+
*.bundle
11+
*.so
12+
*.o
13+
*.a
14+
mkmf.log
15+
.DS_Store

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--require spec_helper

Gemfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in sageone.gemspec
4+
gemspec
5+
6+
group :test do
7+
gem "guard-rspec", require: false
8+
gem 'webmock'
9+
gem 'pry'
10+
gem 'simplecov'
11+
gem 'vcr'
12+
end

Guardfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# A sample Guardfile
2+
# More info at https://github.com/guard/guard#readme
3+
4+
# Note: The cmd option is now required due to the increasing number of ways
5+
# rspec may be run, below are examples of the most common uses.
6+
# * bundler: 'bundle exec rspec'
7+
# * bundler binstubs: 'bin/rspec'
8+
# * spring: 'bin/rsspec' (This will use spring if running and you have
9+
# installed the spring binstubs per the docs)
10+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
11+
# * 'just' rspec: 'rspec'
12+
guard :rspec, cmd: 'bundle exec rspec' do
13+
watch(%r{^spec/.+_spec\.rb$})
14+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
15+
watch('spec/spec_helper.rb') { "spec" }
16+
17+
# Rails example
18+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
20+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
21+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
22+
watch('config/routes.rb') { "spec/routing" }
23+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
24+
watch('spec/rails_helper.rb') { "spec" }
25+
26+
# Capybara features specs
27+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
28+
29+
# Turnip features and steps
30+
watch(%r{^spec/acceptance/(.+)\.feature$})
31+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
32+
end
33+

LICENSE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2020
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2121
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2222
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23-

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SageoneSdk
2+
3+
The `sageone_sdk` gem provides Ruby methods for accessing the Sage One API endpoints.
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
```ruby
10+
gem 'sageone_sdk'
11+
```
12+
13+
And then execute:
14+
15+
$ bundle
16+
17+
Or install it yourself as:
18+
19+
$ gem install sageone_sdk
20+
21+
## Usage
22+
23+
To create a `SageoneSdk::Client`, you need to provide your access_token and signing_secret:
24+
25+
```
26+
@client = SageoneSdk::Client.new({access_token: @access_token,
27+
signing_secret: @signing_secret})
28+
```
29+
30+
Further information about obtaining these is available [here](https://developers.sageone.com/docs/en/v1#overview).
31+
32+
You can then call the required method on the `@client`:
33+
34+
```
35+
@client.bank_accounts
36+
=> #<SageoneSdk::SDataResponse:0x007faaa9eb1760
37+
@data=
38+
{"$totalResults"=>2,
39+
"$startIndex"=>0,
40+
"$itemsPerPage"=>20,
41+
"$resources"=>
42+
[{"id"=>214227,
43+
"account_name"=>"Current",
44+
#...}]
45+
}>
46+
```
47+
48+
49+
## Contributing
50+
51+
1. Fork it ( https://github.com/[my-github-username]/sageone/fork )
52+
2. Create your feature branch (`git checkout -b my-new-feature`)
53+
3. Commit your changes (`git commit -am 'Add some feature'`)
54+
4. Push to the branch (`git push origin my-new-feature`)
55+
5. Create a new Pull Request

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "bundler/gem_tasks"
2+

lib/sageone_sdk.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require "sageone_sdk/client"
2+
require "sageone_sdk/default"
3+
4+
module SageoneSdk
5+
autoload :SDataResponse, "sageone_sdk/sdata_response"
6+
class << self
7+
include SageoneSdk::Configurable
8+
9+
def client
10+
@client = SageoneSdk::Client.new unless defined?(@client)
11+
@client
12+
end
13+
end
14+
end
15+
16+
SageoneSdk.setup

lib/sageone_sdk/authentication.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module SageoneSdk
2+
module Authentication
3+
def token_authenticated?
4+
!!@access_token
5+
end
6+
end
7+
end

lib/sageone_sdk/client.rb

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
require "sawyer"
2+
require "faraday_middleware"
3+
require "sageone_sdk/authentication"
4+
require "sageone_sdk/configurable"
5+
require "sageone_sdk/middleware"
6+
require "sageone_sdk/client/account_types"
7+
require "sageone_sdk/client/bank_accounts"
8+
require "sageone_sdk/client/chart_of_accounts"
9+
require "sageone_sdk/client/contact_types"
10+
require "sageone_sdk/client/contacts"
11+
require "sageone_sdk/client/countries"
12+
require "sageone_sdk/client/expenditures"
13+
require "sageone_sdk/client/expense_methods"
14+
require "sageone_sdk/client/expense_types"
15+
require "sageone_sdk/client/financial_settings"
16+
require "sageone_sdk/client/income_methods"
17+
require "sageone_sdk/client/income_types"
18+
require "sageone_sdk/client/incomes"
19+
require "sageone_sdk/client/journals"
20+
require "sageone_sdk/client/ledger_accounts"
21+
require "sageone_sdk/client/payment_statuses"
22+
require "sageone_sdk/client/period_types"
23+
require "sageone_sdk/client/purchase_invoices"
24+
require "sageone_sdk/client/products"
25+
require "sageone_sdk/client/sales_invoices"
26+
require "sageone_sdk/client/services"
27+
require "sageone_sdk/client/tax_rates"
28+
require "sageone_sdk/client/transactions"
29+
30+
module SageoneSdk
31+
class Client
32+
include SageoneSdk::Authentication
33+
include SageoneSdk::Configurable
34+
include SageoneSdk::Client::AccountTypes
35+
include SageoneSdk::Client::BankAccounts
36+
include SageoneSdk::Client::ChartOfAccounts
37+
include SageoneSdk::Client::ContactTypes
38+
include SageoneSdk::Client::Contacts
39+
include SageoneSdk::Client::Countries
40+
include SageoneSdk::Client::Expenditures
41+
include SageoneSdk::Client::ExpenseMethods
42+
include SageoneSdk::Client::ExpenseTypes
43+
include SageoneSdk::Client::FinancialSettings
44+
include SageoneSdk::Client::IncomeMethods
45+
include SageoneSdk::Client::IncomeTypes
46+
include SageoneSdk::Client::Incomes
47+
include SageoneSdk::Client::Journals
48+
include SageoneSdk::Client::LedgerAccounts
49+
include SageoneSdk::Client::PaymentStatuses
50+
include SageoneSdk::Client::PeriodTypes
51+
include SageoneSdk::Client::PurchaseInvoices
52+
include SageoneSdk::Client::Products
53+
include SageoneSdk::Client::SalesInvoices
54+
include SageoneSdk::Client::Services
55+
include SageoneSdk::Client::TaxRates
56+
include SageoneSdk::Client::Transactions
57+
58+
def initialize(options = {})
59+
SageoneSdk::Configurable.keys.each do |key|
60+
instance_variable_set(:"@#{key}", options[key] || SageoneSdk.instance_variable_get(:"@#{key}"))
61+
end
62+
end
63+
64+
def last_response
65+
@last_response if defined? @last_response
66+
end
67+
68+
def paginate(resource, options = {})
69+
data = get(resource, options)
70+
data
71+
end
72+
73+
def get(path, data={})
74+
request(:get, path, data)
75+
end
76+
77+
def post(path, data={})
78+
request(:post, path, data)
79+
end
80+
81+
def put(path, data={})
82+
request(:put, path, data)
83+
end
84+
85+
def delete(path, data={})
86+
request(:delete, path, data)
87+
end
88+
89+
def request(method, path, data, options = {})
90+
path = File.join("accounts", "v1", path)
91+
@last_response = response = agent.public_send(method, URI::Parser.new.escape(path.to_s), data, options)
92+
response.body
93+
end
94+
95+
def agent
96+
@agent ||= Faraday.new(api_endpoint, faraday_options) do |builder|
97+
builder.request :url_encoded
98+
builder.headers['Accept'] = default_media_type
99+
builder.headers['Content-Type'] = "application/x-www-form-urlencoded"
100+
builder.headers['User-Agent'] = user_agent
101+
if token_authenticated?
102+
builder.authorization 'Bearer', @access_token
103+
end
104+
builder.use SageoneSdk::Middleware::Signature, access_token, signing_secret
105+
builder.use SageoneSdk::Middleware::SDataParser
106+
builder.adapter Faraday.default_adapter
107+
end
108+
end
109+
110+
private
111+
112+
def faraday_options
113+
{}
114+
end
115+
end
116+
end

0 commit comments

Comments
 (0)