myob-api 0.9.5 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2a697621522acb62c1242ba5ccdec10372b9e950
4
- data.tar.gz: 61b3ca85bf3824c07f209bd5b164514e0dc898e2
2
+ SHA256:
3
+ metadata.gz: d048710acd822da3799cfd2035da3068ad12ae6647d4c7be5475ae99ecb803b1
4
+ data.tar.gz: 5dc1c1a9c86d5e6ee6ad7d8c4ae85bdf5ac06e5dfc45160e5180cfec7ba491f2
5
5
  SHA512:
6
- metadata.gz: d855db5829da5bf1d73b7f8a5aff3797261c8d68e93b10952c314782d6ab6b292754b1027e6b37f4fb7f2d2edc8188c3f177dff2b2ad0f4929bda0a7a5d932e5
7
- data.tar.gz: d994ded4f98afc2e716fa67f7e03cdfaaccb1d6927bea7e74e5253286087bbb510a8e33efea80c904a982b3b3b1d0133346c9c98f4ea6db1e17fb9392e887e49
6
+ metadata.gz: c4480da3f7a18c9cd2af73dad237a2786afc426c7cf6f9bb0efed4b019152ae71962d47b726637107ab167213b403c62fd378bfad6ef61906ecf38cca39df52d
7
+ data.tar.gz: 45b1a46d930f711de18787d93d7585275fde4d61354de9e7cbe1de0edf196c1c3b9cd74832ac82aaad5e5ab5540b0f0d6fb2a6a00b62578d158a47519cd55d71
data/README.md CHANGED
@@ -84,6 +84,8 @@ Or if you know which Company File you want to access too:
84
84
  },
85
85
  })
86
86
 
87
+ If you provide a company file, the gem will attempt to connect to MYOB to get the base API subdomain to use for future requests ([learn more](http://developer.myob.com/api/accountright/best-practice-guides/hypermedia-and-uris/)).
88
+
87
89
  ### API Methods
88
90
 
89
91
  #### Company Files
@@ -7,21 +7,25 @@ require 'myob/api/models/company_file'
7
7
  require 'myob/api/models/company'
8
8
 
9
9
  require 'myob/api/models/current_user'
10
+ require 'myob/api/models/superannuation_fund'
10
11
 
11
12
  require 'myob/api/models/contact'
12
13
  require 'myob/api/models/customer'
13
14
  require 'myob/api/models/employee'
15
+ require 'myob/api/models/employee_payment_details'
14
16
  require 'myob/api/models/employee_payroll_details'
15
17
  require 'myob/api/models/employee_standard_pay'
16
18
 
17
19
  require 'myob/api/models/employee_payroll_advice'
18
20
 
21
+ require 'myob/api/models/customer_payment'
19
22
  require 'myob/api/models/invoice'
20
23
  require 'myob/api/models/invoice_item'
21
24
 
22
25
  require 'myob/api/models/payroll_category'
23
26
  require 'myob/api/models/wage'
24
27
  require 'myob/api/models/entitlement'
28
+ require 'myob/api/models/tax_table'
25
29
 
26
30
  require 'myob/api/models/timesheet'
27
31
 
@@ -6,7 +6,7 @@ module Myob
6
6
  class Client
7
7
  include Myob::Api::Helpers
8
8
 
9
- attr_reader :current_company_file, :client
9
+ attr_reader :current_company_file, :client, :current_company_file_url
10
10
 
11
11
  def initialize(options)
12
12
  Myob::Api::Model::Base.subclasses.each {|c| model(c.name.split("::").last)}
@@ -15,16 +15,17 @@ module Myob
15
15
  @consumer = options[:consumer]
16
16
  @access_token = options[:access_token]
17
17
  @refresh_token = options[:refresh_token]
18
- @current_company_file = options[:selected_company_file] || {}
18
+
19
19
  @client = OAuth2::Client.new(@consumer[:key], @consumer[:secret], {
20
20
  :site => 'https://secure.myob.com',
21
21
  :authorize_url => '/oauth2/account/authorize',
22
22
  :token_url => '/oauth2/v1/authorize',
23
23
  })
24
24
 
25
- if options[:company_file]
26
- @current_company_file = select_company_file(options[:company_file])
27
- end
25
+ # on client init, if we have a company file already, get the appropriate base URL for this company file from MYOB
26
+ provided_company_file = options[:selected_company_file] || options[:company_file]
27
+ select_company_file(provided_company_file) if provided_company_file
28
+ @current_company_file ||= {}
28
29
  end
29
30
 
30
31
  def get_access_code_url(params = {})
@@ -40,7 +41,7 @@ module Myob
40
41
  end
41
42
 
42
43
  def headers
43
- token = @current_company_file[:token]
44
+ token = (@current_company_file || {})[:token]
44
45
  if token.nil? || token == ''
45
46
  # if token is blank assume we are using federated login - http://myobapi.tumblr.com/post/109848079164/2015-1-release-notes
46
47
  {
@@ -58,18 +59,39 @@ module Myob
58
59
  end
59
60
  end
60
61
 
62
+ # given some company file credentials, connect to MYOB and get the appropriate company file object.
63
+ # store its ID and token for auth'ing requests, and its URL to ensure we talk to the right MYOB server.
64
+ #
65
+ # `company_file` should be hash. accepted forms:
66
+ #
67
+ # {name: String, username: String, password: String}
68
+ # {id: String, token: String}
61
69
  def select_company_file(company_file)
62
- company_file_id = (company_files.find {|file| file['Name'] == company_file[:name]} || [])['Id']
63
- if company_file_id
70
+ # store the provided company file as an ivar so we can use it for subsequent requests
71
+ # we need the token from it to make the initial request to get company files
72
+ @current_company_file ||= company_file if company_file[:token]
73
+
74
+ selected_company_file = company_files.find {|file|
75
+ if company_file[:name]
76
+ file['Name'] == company_file[:name]
77
+ elsif company_file[:id]
78
+ file['Id'] == company_file[:id]
79
+ end
80
+ }
81
+
82
+ if selected_company_file
64
83
  token = company_file[:token]
65
84
  if (token.nil? || token == '') && !company_file[:username].nil? && company_file[:username] != '' && !company_file[:password].nil?
66
85
  # if we have been given login details, encode them into a token
67
86
  token = Base64.encode64("#{company_file[:username]}:#{company_file[:password]}")
68
87
  end
69
88
  @current_company_file = {
70
- :id => company_file_id,
89
+ :id => selected_company_file['Id'],
71
90
  :token => token
72
91
  }
92
+ @current_company_file_url = selected_company_file['Uri']
93
+ else
94
+ @current_company_file = {}
73
95
  end
74
96
  end
75
97
 
@@ -1,16 +1,21 @@
1
- class String
2
- def underscore
3
- self.gsub(/::/, '/').
4
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
- tr("-", "_").
7
- downcase
8
- end
9
- end
10
-
11
1
  module Myob
12
2
  module Api
3
+
4
+ module RefinedString
5
+ refine String do
6
+ def underscore
7
+ self.gsub(/::/, '/').
8
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
9
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
10
+ tr("-", "_").
11
+ downcase
12
+ end
13
+ end
14
+ end
15
+
13
16
  module Helpers
17
+ using RefinedString
18
+
14
19
  def model(model_name)
15
20
  method_name = model_name.to_s.underscore
16
21
  variable_name = "@#{method_name}_model".to_sym
@@ -23,5 +28,6 @@ module Myob
23
28
  instance_variable_get(variable_name)
24
29
  end
25
30
  end
31
+
26
32
  end
27
33
  end
@@ -3,7 +3,7 @@ module Myob
3
3
  module Model
4
4
  class Base
5
5
 
6
- API_URL = 'https://api.myob.com/accountright/'
6
+ API_URL = 'https://api.myob.com/accountright/' # deprecated except for initial requests - should read from API instead - http://myobapi.tumblr.com/post/141169146113/important-update-accountright-live-cloud-api
7
7
  QUERY_OPTIONS = [:orderby, :top, :skip, :filter]
8
8
 
9
9
  def initialize(client, model_name)
@@ -61,9 +61,13 @@ module Myob
61
61
 
62
62
  def url(object = nil, params = nil)
63
63
  url = if self.model_route == ''
64
- "#{API_URL}"
64
+ API_URL
65
65
  else
66
- "#{API_URL}#{@client.current_company_file[:id]}/#{self.model_route}#{"/#{object['UID']}" if object && object['UID']}"
66
+ if @client && @client.current_company_file_url
67
+ "#{@client.current_company_file_url}/#{self.model_route}#{"/#{object['UID']}" if object && object['UID']}"
68
+ else
69
+ "#{API_URL}#{@client.current_company_file[:id]}/#{self.model_route}#{"/#{object['UID']}" if object && object['UID']}"
70
+ end
67
71
  end
68
72
 
69
73
  if params.is_a?(Hash)
@@ -106,7 +110,11 @@ module Myob
106
110
  end
107
111
 
108
112
  def resource_url
109
- "#{API_URL}#{@client.current_company_file[:id]}/#{self.model_route}"
113
+ if @client && @client.current_company_file_url
114
+ "#{@client.current_company_file_url}/#{self.model_route}"
115
+ else
116
+ "#{API_URL}#{@client.current_company_file[:id]}/#{self.model_route}"
117
+ end
110
118
  end
111
119
 
112
120
  def perform_request(url)
@@ -0,0 +1,11 @@
1
+ module Myob
2
+ module Api
3
+ module Model
4
+ class CustomerPayment < Base
5
+ def model_route
6
+ 'Sale/CustomerPayment'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Myob
2
+ module Api
3
+ module Model
4
+ class EmployeePaymentDetail < Base
5
+ def model_route
6
+ 'Contact/EmployeePaymentDetails'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Myob
2
+ module Api
3
+ module Model
4
+ class SuperannuationFund < Base
5
+ def model_route
6
+ '/Payroll/SuperannuationFund'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Myob
2
+ module Api
3
+ module Model
4
+ class TaxTable < Base
5
+ def model_route
6
+ 'Payroll/PayrollCategory/TaxTable'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Myob
2
2
  module Api
3
- VERSION = "0.9.5"
3
+ VERSION = "0.10.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myob-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Lumley
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-20 00:00:00.000000000 Z
11
+ date: 2020-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -74,7 +74,9 @@ files:
74
74
  - lib/myob/api/models/contact.rb
75
75
  - lib/myob/api/models/current_user.rb
76
76
  - lib/myob/api/models/customer.rb
77
+ - lib/myob/api/models/customer_payment.rb
77
78
  - lib/myob/api/models/employee.rb
79
+ - lib/myob/api/models/employee_payment_details.rb
78
80
  - lib/myob/api/models/employee_payroll_advice.rb
79
81
  - lib/myob/api/models/employee_payroll_details.rb
80
82
  - lib/myob/api/models/employee_standard_pay.rb
@@ -83,6 +85,8 @@ files:
83
85
  - lib/myob/api/models/invoice.rb
84
86
  - lib/myob/api/models/invoice_item.rb
85
87
  - lib/myob/api/models/payroll_category.rb
88
+ - lib/myob/api/models/superannuation_fund.rb
89
+ - lib/myob/api/models/tax_table.rb
86
90
  - lib/myob/api/models/timesheet.rb
87
91
  - lib/myob/api/models/wage.rb
88
92
  - lib/myob/api/version.rb
@@ -91,7 +95,7 @@ homepage: https://github.com/davidlumley/myob-api
91
95
  licenses:
92
96
  - MIT
93
97
  metadata: {}
94
- post_install_message:
98
+ post_install_message:
95
99
  rdoc_options: []
96
100
  require_paths:
97
101
  - lib
@@ -106,10 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
110
  - !ruby/object:Gem::Version
107
111
  version: '0'
108
112
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.2.5
111
- signing_key:
113
+ rubygems_version: 3.1.2
114
+ signing_key:
112
115
  specification_version: 4
113
116
  summary: MYOB AccountRight Live API V2
114
117
  test_files: []
115
- has_rdoc: