myob-api 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -32,14 +32,14 @@ Create an api_client:
32
32
 
33
33
  Or if you know which Company File you want to access too:
34
34
 
35
- api_client = Myob::Api::Client.new({
35
+ api_client = Myob::Api::Client.new({
36
36
  :consumer => {
37
37
  :key => YOUR_CONSUMER_KEY,
38
38
  :secret => YOUR_CONSUMER_SECRET,
39
39
  },
40
40
  :access_token => YOUR_OAUTH_ACCESS_TOKEN,
41
41
  :company_file => {
42
- :id => COMPANY_FILE_ID,
42
+ :name => COMPANY_FILE_NAME,
43
43
  :username => COMPANY_FILE_USERNAME,
44
44
  :password => COMPANY_FILE_PASSWORD,
45
45
  },
@@ -14,12 +14,13 @@ module Myob
14
14
 
15
15
  @consumer = options[:consumer]
16
16
  @access_token = options[:access_token]
17
+ @client = OAuth2::Client.new(@consumer[:key], @consumer[:secret])
18
+
17
19
  if options[:company_file]
18
20
  @current_company_file = select_company_file(options[:company_file])
19
21
  else
20
22
  @current_company_file = {}
21
23
  end
22
- @client = OAuth2::Client.new(@consumer[:key], @consumer[:secret])
23
24
  end
24
25
 
25
26
  def headers
@@ -31,8 +32,9 @@ module Myob
31
32
  end
32
33
 
33
34
  def select_company_file(company_file)
35
+ company_file_id = self.company_file.first('Name' => company_file[:name])['Id']
34
36
  @current_company_file = {
35
- :id => company_file[:id],
37
+ :id => company_file_id,
36
38
  :token => Base64.encode64("#{company_file[:username]}:#{company_file[:password]}"),
37
39
  }
38
40
  end
@@ -14,8 +14,18 @@ module Myob
14
14
  @model_name.to_s
15
15
  end
16
16
 
17
- def all
18
- parse_response(@client.connection.get(self.url, {:headers => @client.headers}))
17
+ def all(query = nil)
18
+ model_data = parse_response(@client.connection.get(self.url, {:headers => @client.headers}))
19
+ if query
20
+ return process_query(model_data, query)
21
+ else
22
+ return model_data
23
+ end
24
+ end
25
+
26
+ def first(query = nil)
27
+ model_data = self.all(query)
28
+ model_data[0] if model_data.length > 0
19
29
  end
20
30
 
21
31
  def url
@@ -32,6 +42,13 @@ module Myob
32
42
  JSON.parse(response.body)
33
43
  end
34
44
 
45
+ def process_query(data, query)
46
+ query.each do |property, value|
47
+ data.select!{|x| x[property] == value}
48
+ end
49
+ data
50
+ end
51
+
35
52
  end
36
53
  end
37
54
  end
@@ -1,5 +1,5 @@
1
1
  module Myob
2
2
  module Api
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myob-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-21 00:00:00.000000000 Z
12
+ date: 2013-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -79,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  segments:
81
81
  - 0
82
- hash: 601466071620978750
82
+ hash: 3491047311971479303
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  segments:
90
90
  - 0
91
- hash: 601466071620978750
91
+ hash: 3491047311971479303
92
92
  requirements: []
93
93
  rubyforge_project:
94
94
  rubygems_version: 1.8.23