octopart-ruby 0.1.0 → 0.1.1

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/Gemfile CHANGED
@@ -1,18 +1,12 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
2
 
9
3
  gem "httparty", "0.9.0"
10
- gem "fakeweb", "1.3.0"
11
4
 
12
- group :development do
5
+ group :development, :test do
13
6
  gem "shoulda", ">= 0"
14
- gem "rdoc", "~> 3.12"
7
+ gem "yard", "~> 0.8.3"
15
8
  gem "bundler", "~> 1.0"
16
9
  gem "jeweler", "~> 1.8.4"
17
- gem "simplecov"
18
- end
10
+ gem "simplecov", "~> 0.7.1"
11
+ gem "fakeweb", "~> 1.3.0"
12
+ end
@@ -37,15 +37,16 @@ GEM
37
37
  multi_json (~> 1.0)
38
38
  simplecov-html (~> 0.7.1)
39
39
  simplecov-html (0.7.1)
40
+ yard (0.8.3)
40
41
 
41
42
  PLATFORMS
42
43
  ruby
43
44
 
44
45
  DEPENDENCIES
45
46
  bundler (~> 1.0)
46
- fakeweb (= 1.3.0)
47
+ fakeweb (~> 1.3.0)
47
48
  httparty (= 0.9.0)
48
49
  jeweler (~> 1.8.4)
49
- rdoc (~> 3.12)
50
50
  shoulda
51
- simplecov
51
+ simplecov (~> 0.7.1)
52
+ yard (~> 0.8.3)
data/Rakefile CHANGED
@@ -13,15 +13,13 @@ require 'rake'
13
13
 
14
14
  require 'jeweler'
15
15
  Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
16
  gem.name = "octopart-ruby"
18
17
  gem.homepage = "http://github.com/parkerboundy/octopart-ruby"
19
18
  gem.license = "MIT"
20
19
  gem.summary = "Ruby wrapper for the Octopart API"
21
20
  gem.description = "Ruby wrapper for the Octopart API"
22
21
  gem.email = "parkerboundy@gmail.com"
23
- gem.authors = ["Parker Boundy"]
24
- # dependencies defined in Gemfile
22
+ gem.authors = ["Parker Boundy"]
25
23
  end
26
24
  Jeweler::RubygemsDotOrgTasks.new
27
25
 
@@ -29,18 +27,10 @@ require 'rake/testtask'
29
27
  Rake::TestTask.new(:test) do |test|
30
28
  test.libs << 'lib' << 'test'
31
29
  test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
30
+ test.verbose = false
33
31
  end
34
32
 
35
-
36
33
  task :default => :test
37
34
 
38
- require 'rdoc/task'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
-
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "octopart-ruby #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
35
+ require 'yard'
36
+ YARD::Rake::YardocTask.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -1,13 +1,16 @@
1
1
  require 'httparty'
2
2
 
3
- # APIKeyNotSet is called when a client is instantiated without an api_key
4
- class APIKeyNotSet < StandardError; end
3
+ # APIKeyNotSetError is called when a client is instantiated without an api_key
4
+ class APIKeyNotSetError < StandardError; end
5
+
6
+ # APIResponseError is called when an API request returns with a code other than 200
7
+ class APIResponseError < StandardError; end
5
8
 
6
9
  module Octopart
7
10
 
8
11
  # api_key - The API key to use
9
12
  def self.api_key
10
- raise APIKeyNotSet if @api_key.nil?
13
+ raise APIKeyNotSetError if @api_key.nil?
11
14
  @api_key
12
15
  end
13
16
 
@@ -1,272 +1,223 @@
1
- # Public: A simple ruby wrapper for the Octopart.com API
1
+ # A simple ruby wrapper for the Octopart.com API
2
2
  # All methods are module methods and should be called on the Octopart module.
3
3
  #
4
- # Examples
5
- #
4
+ # @example
6
5
  # Octopart::Client.new('apikey')
7
- #
8
6
  module Octopart
9
7
 
10
- # Public: An Octopart.com API Client
8
+ # An Octopart.com API Client
11
9
  #
12
- #
13
- # Examples
14
- #
10
+ # @example
15
11
  # Octopart::Client.new('apikey')
16
- #
17
12
  class Client
18
13
 
19
14
  include HTTParty
20
15
  base_uri 'http://octopart.com/api/v2'
21
16
  format :json
22
-
23
-
24
- # Public: The API key for the client
17
+
18
+ # The API key for the client
25
19
  attr_reader :api_key
26
20
 
27
- # Public: Initialize an Octopart client
21
+ # Initialize an Octopart client
28
22
  #
29
- # api_key - The API key to use
30
- # You can get an Octopart API key at http://octopart.com/api/register
23
+ # @note You can get an Octopart API key at http://octopart.com/api/register
24
+ # @param api_key [String] The API key to use
31
25
  def initialize(api_key=nil)
32
26
  @api_key = api_key
33
27
  @api_key ||= Octopart.api_key
34
-
28
+
35
29
  end
36
-
37
-
38
- # Public: Fetch a category object by its id
39
- #
40
- # id - The id of a category object
41
- #
42
- # Examples
30
+
31
+ # Fetch a category object by its id
43
32
  #
33
+ # @param id [String] The id of a category object
34
+ # @return [Hash] A category hash
35
+ # @example
44
36
  # category(4174)
45
- # # => category hash
46
- #
47
- # Returns a category hash
37
+ # # => [Hash]
48
38
  def category(id)
49
39
  if id.is_a? Array
50
40
  categories(id)
51
41
  else
52
- self.class.get('/categories/get', :query => {:id => id, :apikey => @api_key}).parsed_response
42
+ response = self.class.get('/categories/get', :query => {:id => id, :apikey => @api_key})
43
+ validate_response(response)
53
44
  end
54
45
  end
55
46
 
56
-
57
- # Public: Fetch multiple category objects by their ids
58
- #
59
- # ids - Array of category object ids
60
- #
61
- # Examples
47
+ # Fetch multiple category objects by their ids
62
48
  #
49
+ # @param ids [Array] Array of category object ids
50
+ # @return [Hash] A category hash
51
+ # @example
63
52
  # categories([4215,4174,4780])
64
- # # => category hash
65
- #
66
- # Returns a category hash
53
+ # # => [Hash]
67
54
  def categories(ids)
68
55
  raise(ArgumentError, 'ids must be an array') unless ids.is_a?Array
69
- self.class.get('/categories/get_multi', :query => {:ids => "[#{ids.join(",")}]", :apikey => @api_key}).parsed_response
56
+ response = self.class.get('/categories/get_multi', :query => {:ids => "[#{ids.join(",")}]", :apikey => @api_key})
57
+ validate_response(response)
70
58
  end
71
59
 
72
- # Public: Execute search over category objects
73
- #
74
- # q - Query string
75
- # start - Ordinal position of first result. First position is 0. Default is 0
76
- # limit - Maximum number of results to return. Default is 10
77
- #
78
- # Examples
60
+ # Execute search over category objects
79
61
  #
62
+ # @param query [String] Query string
63
+ # @param start [Integer] Ordinal position of first result. First position is 0. Default is 0
64
+ # @param limit [Integer] Maximum number of results to return. Default is 10
65
+ # @return [Hash] A category hash
66
+ # @example
80
67
  # search_categories('resistor')
81
- # # => category hash
82
- #
83
- # Returns a category hash
68
+ # # => [Hash]
84
69
  def search_categories(query, start=0, limit=10)
85
70
  raise(ArgumentError, 'query must be a string > 2 characters and start/limit must be < 100') unless (query.is_a?(String) && query.length > 2 && start.between?(0, 100) &&limit.between?(0,100))
86
- self.class.get('/categories/search', :query => {:q => query, :start => start, :limit => limit, :apikey => @api_key}).parsed_response
71
+ response = self.class.get('/categories/search', :query => {:q => query, :start => start, :limit => limit, :apikey => @api_key})
72
+ validate_response(response)
87
73
  end
88
74
 
89
- # Public: Fetch a part object by its id
90
- #
91
- # uid - the id of a part object
92
- #
93
- # Examples
75
+ # Fetch a part object by its id
94
76
  #
77
+ # @param uid [String] the id of a part object
78
+ # @return [Hash] A part hash
79
+ # @example
95
80
  # part(39619421)
96
- # # => part hash
97
- #
98
- # Returns a part hash
81
+ # # => [Hash]
99
82
  def part(uid)
100
83
  if uid.is_a? Array
101
84
  parts(uid)
102
85
  else
103
- self.class.get('/parts/get', :query => {:uid => uid, :apikey => @api_key}).parsed_response
86
+ response = self.class.get('/parts/get', :query => {:uid => uid, :apikey => @api_key})
87
+ validate_response(response)
104
88
  end
105
89
  end
106
90
 
107
- # Public: Fetch multiple part objects by their ids
108
- #
109
- # uids - JSON encoded list of part object ids. Max number of ids is 100.
110
- #
111
- # Examples
91
+ # Fetch multiple part objects by their ids
112
92
  #
93
+ # @param uids [Array] JSON encoded list of part object ids. Max number of ids is 100.
94
+ # @return [Hash] A part hash
95
+ # @example
113
96
  # parts([39619421,29035751,31119928])
114
- # # => parts hash
115
- #
116
- # Returns a part hash
97
+ # # => [Hash]
117
98
  def parts(uids)
118
99
  raise(ArgumentError, 'uids must be an array') unless uids.is_a?Array
119
- self.class.get('/parts/get_multi', :query => {:uids => "[#{uids.join(",")}]", :apikey => @api_key}).parsed_response
100
+ response = self.class.get('/parts/get_multi', :query => {:uids => "[#{uids.join(",")}]", :apikey => @api_key})
101
+ validate_response(response)
120
102
  end
121
103
 
122
- # Public: Execute search over part objects
123
- #
124
- # query - Query string
125
- # start - Ordinal position of first result. First position is 0. Default is 0. Maximum is 1000.
126
- # limit - Number of results to return. Default is 10. Maximum is 100.
127
- #
128
- # Examples
104
+ # Execute search over part objects
129
105
  #
106
+ # @param query [String] Query string
107
+ # @param start [Integer] Ordinal position of first result. First position is 0. Default is 0. Maximum is 1000.
108
+ # @param limit [Integer] Number of results to return. Default is 10. Maximum is 100.
109
+ # @return [Hash] A part hash
110
+ # @example
130
111
  # search_parts('capacitor')
131
- # # => part hash
112
+ # # => [Hash]
132
113
  #
133
114
  # search_parts('capacitor', 50)
134
- # # => part hash
115
+ # # => [Hash]
135
116
  #
136
117
  # search_parts('capacitor', 100, 25)
137
- # # => part hash
138
- #
139
- # Returns a part hash
118
+ # # => [Hash]
140
119
  def search_parts(query, start=0, limit=10)
141
120
  raise(ArgumentError, 'query must be a string > 2 characters, start < 1000, and limit must be < 100') unless (query.is_a?(String) && query.length > 2 && start.between?(0, 1000) &&limit.between?(0,100))
142
- self.class.get('/parts/search', :query => {:q => query, :start => start, :limit => limit, :apikey => @api_key}).parsed_response
121
+ response = self.class.get('/parts/search', :query => {:q => query, :start => start, :limit => limit, :apikey => @api_key})
122
+ validate_response(response)
143
123
  end
144
124
 
145
- # Public: Suggest a part search query string
146
- #
147
- # q - Query string. Minimum of 2 characters.
148
- # limit - Maximum number of results to return. Default is 5. Maximum is 10.
149
- #
150
- # Examples
125
+ # Suggest a part search query string
151
126
  #
127
+ # @param query [String] Query string. Minimum of 2 characters.
128
+ # @param limit [Integer] Maximum number of results to return. Default is 5. Maximum is 10.
129
+ # @return [Hash] A part hash
130
+ # @example
152
131
  # suggest_parts('sn74f')
153
- # # => parts hash
132
+ # # => [Hash]
154
133
  #
155
134
  # suggest_parts('sn74f', 10)
156
- # # => parts hash
157
- #
158
- # Returns a part hash
135
+ # # => [Hash]
159
136
  def suggest_parts(query, limit=5)
160
137
  raise(ArgumentError, 'query must be a string > 2 characters, and limit must be < 10') unless (query.is_a?(String) && query.length > 2 && limit.between?(0,10))
161
- self.class.get('/parts/suggest', :query => {:q => query.split(' ').join('+'), :limit => limit, :apikey => @api_key}).parsed_response
138
+ response = self.class.get('/parts/suggest', :query => {:q => query.split(' ').join('+'), :limit => limit, :apikey => @api_key})
162
139
  end
163
140
 
164
- # Public: Match (manufacturer,mpn) to part uids
165
- #
166
- # manufacturer_name - Manufacturer name
167
- # mpn - Manufacturer part number
168
- #
169
- # Examples
141
+ # Match (manufacturer,mpn) to part uids
170
142
  #
143
+ # @param manufacturer_name [String] Manufacturer name
144
+ # @param mpn [String] Manufacturer part number
145
+ # @return [Hash] A part hash
146
+ # @example
171
147
  # match_part('Texas Instruments', 'SN74LS240N')
172
- # # => parts hash
173
- #
174
- # Returns a part hash
148
+ # # => [Hash]
175
149
  def match_part(manufacturer_name, mpn)
176
- self.class.get('/parts/match', :query => {:manufacturer_name => manufacturer_name, :mpn => mpn, :apikey => @api_key}).parsed_response
177
- end
178
-
179
- # Public: Helper method for match_part(manufacturer,mpn)
180
- #
181
- # manufacturer_name - Manufacturer name
182
- # mpn - Manufacturer part number
183
- #
184
- # Examples
185
- #
186
- # match_part('Texas Instruments', 'SN74LS240N')
187
- # # => parts hash
188
- #
189
- # Returns a part hash
190
- def match(manufacturer_name, mpn)
191
- match_part(manufacturer_name, mpn)
150
+ response = self.class.get('/parts/match', :query => {:manufacturer_name => manufacturer_name, :mpn => mpn, :apikey => @api_key})
151
+ validate_response(response)
192
152
  end
193
153
 
194
- # Public: Fetch a partattribute object by its id
195
- #
196
- # fieldname - The fieldname of a partattribute object
197
- #
198
- # Examples
154
+ # Fetch a partattribute object by its id
199
155
  #
156
+ # @param fieldname [String] The fieldname of a partattribute object
157
+ # @return [Hash] A part attribute hash
158
+ # @example
200
159
  # part_attribute('capacitance')
201
- # # => partattribute hash
202
- #
203
- # Returns a partattribute hash
160
+ # # => [Hash]
204
161
  def part_attribute(fieldname)
205
162
  if fieldname.is_a? Array
206
163
  part_attributes(fieldname)
207
164
  else
208
- self.class.get('/partattributes/get', :query => {:fieldname => fieldname, :apikey => @api_key}).parsed_response
165
+ response = self.class.get('/partattributes/get', :query => {:fieldname => fieldname, :apikey => @api_key})
166
+ validate_response(response)
209
167
  end
210
168
  end
211
169
 
212
- # Public: Fetch multiple partattribute objects by their ids
213
- #
214
- # fieldnames - The fieldnames of a partattribute objects
215
- #
216
- # Examples
170
+ # Fetch multiple partattribute objects by their ids
217
171
  #
172
+ # @param fieldnames [Array] The fieldnames of a partattribute objects
173
+ # @return [Hash] A part attribute hash
174
+ # @example
218
175
  # part_attributes(['capacitance', 'resistance'])
219
176
  # # => partattribute hash
220
- #
221
- # Returns a partattribute hash
222
177
  def part_attributes(fieldnames)
223
178
  raise(ArgumentError, 'fieldnames must be an array') unless fieldnames.is_a?Array
224
- self.class.get('/partattributes/get_multi', :query => {:fieldnames => "["+fieldnames.map{|v| "\"#{v}\""}.join(',')+"]", :apikey => @api_key}).parsed_response
179
+ response = self.class.get('/partattributes/get_multi', :query => {:fieldnames => "["+fieldnames.map{|v| "\"#{v}\""}.join(',')+"]", :apikey => @api_key})
180
+ validate_response(response)
225
181
  end
226
182
 
227
- # Public: Match lines of a BOM to parts
228
- #
229
- # lines - hash made up of the following optional parameters:
230
- # q - Free form query
231
- # mpn - MPN string
232
- # manufacturer - Manufacturer name
233
- # sku - Supplier SKU string
234
- # supplier - Supplier name
235
- # mpn_or_sku - Match on MPN or SKU
236
- # start=0 - Ordinal position of first item
237
- # limit=3 - Maximum number of items to return
238
- # reference - Arbitrary reference string to differentiate results
239
- #
240
- # Examples
241
- #
183
+ # Match lines of a BOM to parts
184
+ #
185
+ # @param lines [Hash] hash made up of the following optional parameters:
186
+ # @option lines q [String] Free form query
187
+ # @option lines mpn [String] MPN string
188
+ # @option lines manufacturer [String] Manufacturer name
189
+ # @option lines sku [String] Supplier SKU string
190
+ # @option lines supplier [String] Supplier name
191
+ # @option lines mpn_or_sku [String] Match on MPN or SKU
192
+ # @option lines start [Integer] Ordinal position of first item
193
+ # @option lines limit [Integer] Maximum number of items to return
194
+ # @option lines reference [String] Arbitrary reference string to differentiate results
195
+ # @return [Hash] A match hash
196
+ # @example
242
197
  # bom_match({"mpn_or_sku"=> "60K6871", "manufacturer" => "Texas Instruments"})
243
- # # => match hash
244
- #
245
- # Returns a match hash
198
+ # # => [Hash]
246
199
  def bom_match(lines)
247
200
  raise(ArgumentError, 'lines must be a hash') unless lines.is_a?(::Hash)
248
- self.class.get('/bom/match', :query => {:lines => "[{"+lines.map{|k,v| "\"#{k}\":\"#{v}\""}.join(',')+"}]", :apikey => @api_key}).parsed_response
201
+ response = self.class.get('/bom/match', :query => {:lines => "[{"+lines.map{|k,v| "\"#{k}\":\"#{v}\""}.join(',')+"}]", :apikey => @api_key})
202
+ validate_response(response)
249
203
  end
250
204
 
251
- # Public: Helper method for searches
252
- #
253
- # type - String name of the type
254
- # query - Query string
255
- # start - Ordinal position of first result. First position is 0. Default is 0. Maximum is 1000.
256
- # limit - Number of results to return. Default is 10. Maximum is 100.
257
- #
258
- # Examples
205
+ # Helper method for searches
259
206
  #
207
+ # @param type [String] String name of the type
208
+ # @param query [String] Query string
209
+ # @param start [Integer] Ordinal position of first result. First position is 0. Default is 0. Maximum is 1000.
210
+ # @param limit [Integer] Number of results to return. Default is 10. Maximum is 100.
211
+ # @return [Hash] A part hash
212
+ # @example
260
213
  # search_parts('parts', 'capacitor')
261
- # # => part hash
214
+ # # => [Hash]
262
215
  #
263
216
  # search_parts('categories', 'capacitor', 50)
264
- # # => part hash
217
+ # # => [Hash]
265
218
  #
266
219
  # search_parts('parts', 'capacitor', 100, 25)
267
- # # => part hash
268
- #
269
- # Returns a part hash
220
+ # # => [Hash]
270
221
  def search(type, query, start=0, limit=10)
271
222
  raise(ArgumentError, 'query must be a string > 2 characters and start/limit must be < 100') unless (query.is_a?(String) && query.length > 2 && start.between?(0, 100) &&limit.between?(0,100))
272
223
  if type.downcase == 'part' || type.downcase == 'parts'
@@ -278,6 +229,13 @@ module Octopart
278
229
  end
279
230
  end
280
231
 
232
+ alias_method :match, :match_part
233
+
234
+ protected
235
+ def validate_response(response)
236
+ response.code == 200 ? response.parsed_response : raise(APIResponseError, response.code)
237
+ end
238
+
281
239
  end
282
240
 
283
- end
241
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "octopart-ruby"
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Parker Boundy"]
@@ -53,29 +53,29 @@ Gem::Specification.new do |s|
53
53
 
54
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
55
  s.add_runtime_dependency(%q<httparty>, ["= 0.9.0"])
56
- s.add_runtime_dependency(%q<fakeweb>, ["= 1.3.0"])
57
56
  s.add_development_dependency(%q<shoulda>, [">= 0"])
58
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
57
+ s.add_development_dependency(%q<yard>, ["~> 0.8.3"])
59
58
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
60
59
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
61
- s.add_development_dependency(%q<simplecov>, [">= 0"])
60
+ s.add_development_dependency(%q<simplecov>, ["~> 0.7.1"])
61
+ s.add_development_dependency(%q<fakeweb>, ["~> 1.3.0"])
62
62
  else
63
63
  s.add_dependency(%q<httparty>, ["= 0.9.0"])
64
- s.add_dependency(%q<fakeweb>, ["= 1.3.0"])
65
64
  s.add_dependency(%q<shoulda>, [">= 0"])
66
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
+ s.add_dependency(%q<yard>, ["~> 0.8.3"])
67
66
  s.add_dependency(%q<bundler>, ["~> 1.0"])
68
67
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
69
- s.add_dependency(%q<simplecov>, [">= 0"])
68
+ s.add_dependency(%q<simplecov>, ["~> 0.7.1"])
69
+ s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
70
70
  end
71
71
  else
72
72
  s.add_dependency(%q<httparty>, ["= 0.9.0"])
73
- s.add_dependency(%q<fakeweb>, ["= 1.3.0"])
74
73
  s.add_dependency(%q<shoulda>, [">= 0"])
75
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
74
+ s.add_dependency(%q<yard>, ["~> 0.8.3"])
76
75
  s.add_dependency(%q<bundler>, ["~> 1.0"])
77
76
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
78
- s.add_dependency(%q<simplecov>, [">= 0"])
77
+ s.add_dependency(%q<simplecov>, ["~> 0.7.1"])
78
+ s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
79
79
  end
80
80
  end
81
81
 
@@ -7,7 +7,7 @@ class TestOctopartRuby < Test::Unit::TestCase
7
7
  should "require an api key" do
8
8
  Octopart.api_key = nil
9
9
 
10
- assert_raise APIKeyNotSet do
10
+ assert_raise APIKeyNotSetError do
11
11
  Octopart::Client.new()
12
12
  end
13
13
  end
@@ -93,6 +93,14 @@ class TestOctopartRuby < Test::Unit::TestCase
93
93
  assert_equal 10, search["results"].count
94
94
  end
95
95
 
96
+ should "respond to error codes properly" do
97
+ FakeWeb.register_uri(:get, "http://octopart.com/api/v2/categories/get?id=4174&apikey=123456789", :body => fixture_file("category.json"), :status => ["404", "Not Found"])
98
+
99
+ assert_raise APIResponseError do
100
+ @client.category(4174)
101
+ end
102
+ end
103
+
96
104
  end
97
105
 
98
106
  context "Part API Methods" do
@@ -160,6 +168,14 @@ class TestOctopartRuby < Test::Unit::TestCase
160
168
  match = @client.match_part('texas instruments', 'SN74LS240N')
161
169
 
162
170
  assert_not_nil match
171
+ end
172
+
173
+ should "respond to error codes properly" do
174
+ FakeWeb.register_uri(:get, "http://octopart.com/api/v2/parts/get?uid=39619421&apikey=123456789", :body => fixture_file("part.json"), :status => ["404", "Not Found"])
175
+
176
+ assert_raise APIResponseError do
177
+ @client.part(39619421)
178
+ end
163
179
  end
164
180
 
165
181
  end
@@ -196,6 +212,14 @@ class TestOctopartRuby < Test::Unit::TestCase
196
212
  assert_equal 2, attributes.count
197
213
  assert_equal "number", attributes.last["type"]
198
214
  end
215
+
216
+ should "respond to error codes properly" do
217
+ FakeWeb.register_uri(:get, "http://octopart.com/api/v2/partattributes/get?fieldname=capacitance&apikey=123456789", :body => fixture_file("attribute.json"), :status => ["404", "Not Found"])
218
+
219
+ assert_raise APIResponseError do
220
+ @client.part_attribute('capacitance')
221
+ end
222
+ end
199
223
 
200
224
  end
201
225
 
@@ -216,6 +240,14 @@ class TestOctopartRuby < Test::Unit::TestCase
216
240
 
217
241
  assert_not_nil bom
218
242
  end
243
+
244
+ should "respond to error codes properly" do
245
+ FakeWeb.register_uri(:get, "http://octopart.com/api/v2/bom/match?lines=%5B%7B%22mpn%22%3A%22SN74LS240N%22%2C%22manufacturer%22%3A%22Texas%20Instruments%22%7D%5D&apikey=123456789", :body => fixture_file("bom.json"), :status => ["404", "Not Found"])
246
+
247
+ assert_raise APIResponseError do
248
+ @client.bom_match({"mpn" => "SN74LS240N", "manufacturer" => "Texas Instruments"})
249
+ end
250
+ end
219
251
 
220
252
  end
221
253
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopart-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-12-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70103207648740 !ruby/object:Gem::Requirement
16
+ requirement: &70163619218620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,21 +21,10 @@ dependencies:
21
21
  version: 0.9.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70103207648740
25
- - !ruby/object:Gem::Dependency
26
- name: fakeweb
27
- requirement: &70103207636060 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - =
31
- - !ruby/object:Gem::Version
32
- version: 1.3.0
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *70103207636060
24
+ version_requirements: *70163619218620
36
25
  - !ruby/object:Gem::Dependency
37
26
  name: shoulda
38
- requirement: &70103207629620 !ruby/object:Gem::Requirement
27
+ requirement: &70163619217920 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - ! '>='
@@ -43,21 +32,21 @@ dependencies:
43
32
  version: '0'
44
33
  type: :development
45
34
  prerelease: false
46
- version_requirements: *70103207629620
35
+ version_requirements: *70163619217920
47
36
  - !ruby/object:Gem::Dependency
48
- name: rdoc
49
- requirement: &70103207608060 !ruby/object:Gem::Requirement
37
+ name: yard
38
+ requirement: &70163619217100 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ~>
53
42
  - !ruby/object:Gem::Version
54
- version: '3.12'
43
+ version: 0.8.3
55
44
  type: :development
56
45
  prerelease: false
57
- version_requirements: *70103207608060
46
+ version_requirements: *70163619217100
58
47
  - !ruby/object:Gem::Dependency
59
48
  name: bundler
60
- requirement: &70103207603920 !ruby/object:Gem::Requirement
49
+ requirement: &70163619216340 !ruby/object:Gem::Requirement
61
50
  none: false
62
51
  requirements:
63
52
  - - ~>
@@ -65,10 +54,10 @@ dependencies:
65
54
  version: '1.0'
66
55
  type: :development
67
56
  prerelease: false
68
- version_requirements: *70103207603920
57
+ version_requirements: *70163619216340
69
58
  - !ruby/object:Gem::Dependency
70
59
  name: jeweler
71
- requirement: &70103207600080 !ruby/object:Gem::Requirement
60
+ requirement: &70163619215560 !ruby/object:Gem::Requirement
72
61
  none: false
73
62
  requirements:
74
63
  - - ~>
@@ -76,18 +65,29 @@ dependencies:
76
65
  version: 1.8.4
77
66
  type: :development
78
67
  prerelease: false
79
- version_requirements: *70103207600080
68
+ version_requirements: *70163619215560
80
69
  - !ruby/object:Gem::Dependency
81
70
  name: simplecov
82
- requirement: &70103207596280 !ruby/object:Gem::Requirement
71
+ requirement: &70163619214720 !ruby/object:Gem::Requirement
83
72
  none: false
84
73
  requirements:
85
- - - ! '>='
74
+ - - ~>
86
75
  - !ruby/object:Gem::Version
87
- version: '0'
76
+ version: 0.7.1
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70163619214720
80
+ - !ruby/object:Gem::Dependency
81
+ name: fakeweb
82
+ requirement: &70163619214080 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.3.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70103207596280
90
+ version_requirements: *70163619214080
91
91
  description: Ruby wrapper for the Octopart API
92
92
  email: parkerboundy@gmail.com
93
93
  executables: []
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: -3541336794183850105
138
+ hash: 2149321309424623997
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  none: false
141
141
  requirements: