crunch-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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjY2MGNmNzUxODY5OTM1ZjhiNGMzMGQ1NTBkNDA4MTRkNDM4ODA2Mw==
5
+ data.tar.gz: !binary |-
6
+ OGNjZDA0MTY3ODc0ODFjM2NiMzEzNDZhY2NmNzI5NjA5NzJlNjg5YQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZmU5MDdkODBhNzU1OThlMDAxODY3NDAwZjc2NTEzYjY1M2JhNTk1NDkzYjM3
10
+ MDUyOWU3NTM2OGVhYmZjMjk4YzJlMDYyNzU0MTJhNTEwOWNlYmJhYTVkNmM1
11
+ YjU0MDgzNTBlOGYzMTI0OWExODgzMjVmOGVhYTY5ZDRhM2NmN2I=
12
+ data.tar.gz: !binary |-
13
+ ZDA1NWQ0YjI4YWJlMmI2YzI5MzNiNmViYjk0YzJjMDI1OTJjZmUwYTMzZGQx
14
+ ZTE4MTJkNjYxMmQ0YWI2ZmM0MDJjYTcxOGMyNTgwZWYzMDdhZGJmNWYxYzEy
15
+ ZWEzNWUyNTgxYTBkNDBjZjBkMmMxNmEwMGI5OGE4MDY4ZDU3MGM=
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
@@ -3,14 +3,19 @@ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'crunch-api/version'
5
5
 
6
+ fullname = `git config --get user.name`.chomp
7
+ email = `git config --get user.email`.chomp
8
+ login = `git config --get github.user`.chomp
9
+ gem_name = "crunch-api"
10
+
6
11
  Gem::Specification.new do |spec|
7
- spec.name = "crunch-api"
12
+ spec.name = gem_name
8
13
  spec.version = CrunchApi::VERSION
9
- spec.authors = ["Aaron Chambers"]
10
- spec.email = ["achambers@gmail.com"]
14
+ spec.authors = [ "#{fullname}" ]
15
+ spec.email = "#{email}"
11
16
  spec.description = %q{A Ruby interface to the Crunch Accounting API}
12
17
  spec.summary = spec.description
13
- spec.homepage = ""
18
+ spec.homepage = "http://github.com/#{login}/#{gem_name}"
14
19
  spec.license = "MIT"
15
20
 
16
21
  spec.files = `git ls-files`.split($/)
@@ -31,7 +31,18 @@ module CrunchApi
31
31
 
32
32
  response = token.get(uri)
33
33
 
34
- parse_xml(response.body).collect{|xml| new(xml)}
34
+ parse_xml(response.body).collect{|attributes| new(attributes)}
35
+ end
36
+
37
+ def self.for_id(id)
38
+ consumer = OAuth::Consumer.new(CrunchApi.options[:consumer_key], CrunchApi.options[:consumer_secret], {})
39
+ token = OAuth::AccessToken.new(consumer, CrunchApi.options[:oauth_token], CrunchApi.options[:oauth_token_secret])
40
+
41
+ uri = "#{CrunchApi.options[:endpoint]}#{path}/#{id}"
42
+
43
+ response = token.get(uri)
44
+
45
+ new(parse_xml(response.body)) unless errors?(response.body)
35
46
  end
36
47
 
37
48
  private
@@ -41,7 +52,15 @@ module CrunchApi
41
52
  end
42
53
 
43
54
  def self.parse_xml(xml)
44
- Nori.new(:convert_tags_to => lambda { |tag| tag.snakecase.to_sym }).parse(xml)[:crunch_message][:suppliers][:supplier]
55
+ to_hash(xml)[:crunch_message][:suppliers][:supplier]
56
+ end
57
+
58
+ def self.to_hash(xml)
59
+ Nori.new(:convert_tags_to => lambda { |tag| tag.snakecase.to_sym }).parse(xml)
60
+ end
61
+
62
+ def self.errors?(xml)
63
+ to_hash(xml)[:crunch_message].fetch(:errors, []).length > 0
45
64
  end
46
65
  end
47
66
  end
@@ -1,3 +1,3 @@
1
1
  module CrunchApi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,53 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://demo.crunch.co.uk/crunch-core/seam/resource/rest/api/suppliers/999
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - OAuth gem v0.4.7
14
+ Authorization:
15
+ - OAuth oauth_consumer_key="aaron_chambers", oauth_nonce="xxx",
16
+ oauth_signature="xxx", oauth_signature_method="HMAC-SHA1",
17
+ oauth_timestamp="1368868641", oauth_token="xxx",
18
+ oauth_version="1.0"
19
+ response:
20
+ status:
21
+ code: 200
22
+ message: OK
23
+ headers:
24
+ Date:
25
+ - Sat, 18 May 2013 09:17:19 GMT
26
+ Server:
27
+ - Apache
28
+ Set-Cookie:
29
+ - JSESSIONID=uSyPzbvUAZJaqsQ6cR+WDtnC.undefined; Path=/crunch-core; Secure
30
+ Cache-Control:
31
+ - no-cache
32
+ Content-Length:
33
+ - '376'
34
+ Access-Control-Allow-Origin:
35
+ - ! '*'
36
+ Access-Control-Allow-Headers:
37
+ - Origin, Content-Type, Accept, X-Requested-With, oauth_consumer_key, oauth_token,
38
+ oauth_signature_method, oauth_signature, oauth_timestamp, oauth_nonce, oauth_version,
39
+ Authorization
40
+ Connection:
41
+ - close
42
+ Content-Type:
43
+ - application/*+xml
44
+ body:
45
+ encoding: US-ASCII
46
+ string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><crunchMessage
47
+ xmlns="http://api.crunch.co.uk/rest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
48
+ outcome="failure" xsi:schemaLocation="http://api.crunch.co.uk/rest"><errors
49
+ count="0"><error><cause>Cannot find supplier with id 999 for Crunch client
50
+ Aaron Chambers Test Ltd</cause></error></errors></crunchMessage>
51
+ http_version:
52
+ recorded_at: Sat, 18 May 2013 09:17:21 GMT
53
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://demo.crunch.co.uk/crunch-core/seam/resource/rest/api/suppliers/711
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - OAuth gem v0.4.7
14
+ Authorization:
15
+ - OAuth oauth_consumer_key="aaron_chambers", oauth_nonce="xxx",
16
+ oauth_signature="xxx", oauth_signature_method="HMAC-SHA1",
17
+ oauth_timestamp="1368738955", oauth_token="xxx",
18
+ oauth_version="1.0"
19
+ response:
20
+ status:
21
+ code: 200
22
+ message: OK
23
+ headers:
24
+ Date:
25
+ - Thu, 16 May 2013 21:15:56 GMT
26
+ Server:
27
+ - Apache
28
+ Set-Cookie:
29
+ - JSESSIONID=4xR5F4z8IaBbWglFnophJClD.undefined; Path=/crunch-core; Secure
30
+ Cache-Control:
31
+ - no-cache
32
+ Content-Length:
33
+ - '581'
34
+ Access-Control-Allow-Origin:
35
+ - ! '*'
36
+ Access-Control-Allow-Headers:
37
+ - Origin, Content-Type, Accept, X-Requested-With, oauth_consumer_key, oauth_token,
38
+ oauth_signature_method, oauth_signature, oauth_timestamp, oauth_nonce, oauth_version,
39
+ Authorization
40
+ Connection:
41
+ - close
42
+ Content-Type:
43
+ - application/*+xml
44
+ body:
45
+ encoding: US-ASCII
46
+ string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><crunchMessage
47
+ xmlns="http://api.crunch.co.uk/rest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
48
+ outcome="success" xsi:schemaLocation="http://api.crunch.co.uk/rest"><suppliers
49
+ count="1" firstResult="0"><supplier supplierId="711" defaultExpenseType="INTERNET"
50
+ resourceUrl="/crunch-core/seam/resource/rest/api/suppliers/711"><name>BT</name><contactName>Sam
51
+ Smith</contactName><email>sam@bt.com</email><website>bt.com</website><telephone>0712345678</telephone><fax>0212345678</fax></supplier></suppliers></crunchMessage>
52
+ http_version:
53
+ recorded_at: Thu, 16 May 2013 21:15:56 GMT
54
+ recorded_with: VCR 2.4.0
@@ -3,32 +3,32 @@ require_relative '../../test_helper'
3
3
  describe CrunchApi::Supplier do
4
4
  describe "Initialization" do
5
5
  [:name, :contact_name, :email, :website, :telephone, :fax].each do |attribute|
6
- it "should set the attribute for #{attribute}" do
6
+ it "sets the attribute for #{attribute}" do
7
7
  supplier = CrunchApi::Supplier.new(attribute.to_sym => "foo")
8
8
 
9
9
  supplier.send(attribute).must_equal "foo"
10
10
  end
11
11
  end
12
12
 
13
- it "should set the attribute for id" do
13
+ it "sets the attribute for id" do
14
14
  supplier = CrunchApi::Supplier.new(:@supplierId => "foo")
15
15
 
16
16
  supplier.id.must_equal "foo"
17
17
  end
18
18
 
19
- it "should set the attribute for uri" do
19
+ it "sets the attribute for uri" do
20
20
  supplier = CrunchApi::Supplier.new(:@resourceUrl => "foo")
21
21
 
22
22
  supplier.uri.must_equal "foo"
23
23
  end
24
24
 
25
- it "should set the attribute for default expense type" do
25
+ it "sets the attribute for default expense type" do
26
26
  supplier = CrunchApi::Supplier.new(:@defaultExpenseType => "foo")
27
27
 
28
28
  supplier.default_expense_type.must_equal "foo"
29
29
  end
30
30
 
31
- it "should set the attribute for unknown supplier" do
31
+ it "sets the attribute for unknown supplier" do
32
32
  supplier = CrunchApi::Supplier.new(:@unknownSupplier => "true")
33
33
 
34
34
  supplier.unknown_supplier?.must_equal true
@@ -42,7 +42,7 @@ describe CrunchApi::Supplier do
42
42
  end
43
43
  end
44
44
 
45
- it "should call the correct resource" do
45
+ it "calls the correct resource" do
46
46
  VCR.use_cassette('get_suppliers_success') do
47
47
  CrunchApi::Supplier.all
48
48
 
@@ -50,7 +50,7 @@ describe CrunchApi::Supplier do
50
50
  end
51
51
  end
52
52
 
53
- it "should return an array of suppliers" do
53
+ it "returns an array of suppliers" do
54
54
  VCR.use_cassette('get_suppliers_success') do
55
55
  suppliers = CrunchApi::Supplier.all
56
56
 
@@ -61,4 +61,41 @@ describe CrunchApi::Supplier do
61
61
  end
62
62
  end
63
63
  end
64
+
65
+ describe "GET /suppliers/{id}" do
66
+ before do
67
+ CrunchApi.configure do |config|
68
+ config.endpoint = "https://demo.crunch.co.uk"
69
+ end
70
+ end
71
+
72
+ it "calls the correct resource" do
73
+ VCR.use_cassette('get_supplier_by_id_success') do
74
+ CrunchApi::Supplier.for_id(711)
75
+
76
+ assert_requested(:get, 'https://demo.crunch.co.uk/crunch-core/seam/resource/rest/api/suppliers/711')
77
+ end
78
+ end
79
+
80
+ describe "an existing supplier" do
81
+ it "returns a supplier" do
82
+ VCR.use_cassette('get_supplier_by_id_success') do
83
+ supplier = CrunchApi::Supplier.for_id(711)
84
+
85
+ supplier.must_be_kind_of CrunchApi::Supplier
86
+ supplier.name.must_equal "BT"
87
+ end
88
+ end
89
+ end
90
+
91
+ describe "an unknown supplier" do
92
+ it "returns nil" do
93
+ VCR.use_cassette('get_supplier_by_id_failure') do
94
+ supplier = CrunchApi::Supplier.for_id(999)
95
+
96
+ supplier.must_be_nil
97
+ end
98
+ end
99
+ end
100
+ end
64
101
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crunch-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Aaron Chambers
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-16 00:00:00.000000000 Z
11
+ date: 2013-05-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: oauth
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: nori
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: nokogiri
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: bundler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: webmock
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ! '>='
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ! '>='
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: vcr
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
@@ -118,19 +104,18 @@ dependencies:
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ~>
124
109
  - !ruby/object:Gem::Version
125
110
  version: '2.4'
126
111
  description: A Ruby interface to the Crunch Accounting API
127
- email:
128
- - achambers@gmail.com
112
+ email: achambers@gmail.com
129
113
  executables: []
130
114
  extensions: []
131
115
  extra_rdoc_files: []
132
116
  files:
133
117
  - .gitignore
118
+ - .travis.yml
134
119
  - Gemfile
135
120
  - LICENSE.txt
136
121
  - README.md
@@ -140,44 +125,41 @@ files:
140
125
  - lib/crunch-api/default.rb
141
126
  - lib/crunch-api/supplier.rb
142
127
  - lib/crunch-api/version.rb
128
+ - test/fixtures/vcr_cassettes/get_supplier_by_id_failure.yml
129
+ - test/fixtures/vcr_cassettes/get_supplier_by_id_success.yml
143
130
  - test/fixtures/vcr_cassettes/get_suppliers_success.yml
144
131
  - test/lib/crunch-api/default_test.rb
145
132
  - test/lib/crunch-api/supplier_test.rb
146
133
  - test/lib/crunch-api/version_test.rb
147
134
  - test/lib/crunch-api_test.rb
148
135
  - test/test_helper.rb
149
- homepage: ''
136
+ homepage: http://github.com/achambers/crunch-api
150
137
  licenses:
151
138
  - MIT
139
+ metadata: {}
152
140
  post_install_message:
153
141
  rdoc_options: []
154
142
  require_paths:
155
143
  - lib
156
144
  required_ruby_version: !ruby/object:Gem::Requirement
157
- none: false
158
145
  requirements:
159
146
  - - ! '>='
160
147
  - !ruby/object:Gem::Version
161
148
  version: '0'
162
- segments:
163
- - 0
164
- hash: -2400216506421897793
165
149
  required_rubygems_version: !ruby/object:Gem::Requirement
166
- none: false
167
150
  requirements:
168
151
  - - ! '>='
169
152
  - !ruby/object:Gem::Version
170
153
  version: '0'
171
- segments:
172
- - 0
173
- hash: -2400216506421897793
174
154
  requirements: []
175
155
  rubyforge_project:
176
- rubygems_version: 1.8.24
156
+ rubygems_version: 2.0.3
177
157
  signing_key:
178
- specification_version: 3
158
+ specification_version: 4
179
159
  summary: A Ruby interface to the Crunch Accounting API
180
160
  test_files:
161
+ - test/fixtures/vcr_cassettes/get_supplier_by_id_failure.yml
162
+ - test/fixtures/vcr_cassettes/get_supplier_by_id_success.yml
181
163
  - test/fixtures/vcr_cassettes/get_suppliers_success.yml
182
164
  - test/lib/crunch-api/default_test.rb
183
165
  - test/lib/crunch-api/supplier_test.rb