etsy 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ if RUBY_VERSION < '1.9'
6
+ gem 'activesupport', '< 4.0'
7
+ end
data/README.md CHANGED
@@ -29,7 +29,7 @@ It will likely work with higher versions, but this is unproven.
29
29
  ### Public Mode
30
30
 
31
31
  The Etsy API has two modes: public, and authenticated. Public mode only requires an
32
- API key (available from http://developer.etsy.com):
32
+ API key (available from http://developer.etsy.com ):
33
33
 
34
34
  require 'rubygems'
35
35
  require 'etsy'
@@ -29,5 +29,5 @@ Gem::Specification.new do |gem|
29
29
  # on shoulda/context.rb:7
30
30
  # But then when you load active_support, shoulda-context decides
31
31
  # to load MiniTest
32
- gem.add_development_dependency 'minitest'
32
+ gem.add_development_dependency 'minitest', "=4.7.4"
33
33
  end
@@ -81,6 +81,17 @@ module Etsy
81
81
  @environment = environment
82
82
  @host = (environment == :sandbox) ? SANDBOX_HOST : PRODUCTION_HOST
83
83
  end
84
+
85
+ def self.protocol=(protocol)
86
+ unless ["http", "https"].include?(protocol.to_s)
87
+ raise(ArgumentError, "protocol must be set to either 'http' or 'https'")
88
+ end
89
+ @protocol = protocol.to_s
90
+ end
91
+
92
+ def self.protocol
93
+ @protocol || "http"
94
+ end
84
95
 
85
96
  # The currently configured environment.
86
97
  #
@@ -13,7 +13,13 @@ module Etsy
13
13
  end
14
14
 
15
15
  def client # :nodoc:
16
- @client ||= Net::HTTP.new(@host)
16
+ if @client
17
+ return @client
18
+ else
19
+ @client = Net::HTTP.new(@host, Etsy.protocol == "http" ? 80 : 443)
20
+ @client.use_ssl = true if Etsy.protocol == "https"
21
+ return @client
22
+ end
17
23
  end
18
24
 
19
25
  # Fetch a raw response from the specified endpoint
@@ -26,9 +26,17 @@ module Etsy
26
26
  end
27
27
 
28
28
  def self.create(listing, image_path, options = {})
29
+ options.merge!(:require_secure => true)
29
30
  options[:image] = File.new(image_path)
30
31
  options[:multipart] = true
31
32
  post("/listings/#{listing.id}/images", options)
32
33
  end
34
+
35
+ # Delete image
36
+ #
37
+ def self.destroy(listing, image, options = {})
38
+ options.merge!(:require_secure => true)
39
+ delete("/listings/#{listing.id}/images/#{image.id}", options)
40
+ end
33
41
  end
34
42
  end
@@ -57,6 +57,11 @@ module Etsy
57
57
  options.merge!(:require_secure => true)
58
58
  put("/listings/#{listing.id}", options)
59
59
  end
60
+
61
+ def self.destroy(listing, options = {})
62
+ options.merge!(:require_secure => true)
63
+ delete("/listings/#{listing.id}", options)
64
+ end
60
65
 
61
66
  # Retrieve one or more listings by ID:
62
67
  #
@@ -83,6 +83,10 @@ module Etsy
83
83
  def put(endpoint, options={})
84
84
  Request.put(endpoint, options)
85
85
  end
86
+
87
+ def delete(endpoint, options={})
88
+ Request.delete(endpoint, options)
89
+ end
86
90
 
87
91
  def find_one_or_more(endpoint, identifiers_and_options)
88
92
  options = options_from(identifiers_and_options)
@@ -22,6 +22,13 @@ module Etsy
22
22
  request = Request.new(resource_path, parameters)
23
23
  Response.new(request.put)
24
24
  end
25
+
26
+ def self.delete(resource_path, parameters = {})
27
+ request = Request.new(resource_path, parameters)
28
+ Response.new(request.delete)
29
+ end
30
+
31
+
25
32
 
26
33
  # Create a new request for the resource with optional parameters
27
34
  def initialize(resource_path, parameters = {})
@@ -68,6 +75,10 @@ module Etsy
68
75
  def put
69
76
  client.put(endpoint_url)
70
77
  end
78
+
79
+ def delete
80
+ client.delete(endpoint_url)
81
+ end
71
82
 
72
83
  def client # :nodoc:
73
84
  @client ||= secure? ? secure_client : basic_client
@@ -49,6 +49,11 @@ module Etsy
49
49
  []
50
50
  end
51
51
  end
52
+
53
+ # Total number of results of the request
54
+ def total
55
+ @total ||= to_hash['count']
56
+ end
52
57
 
53
58
  def success?
54
59
  !!(code =~ /2\d\d/)
@@ -24,7 +24,7 @@ module Etsy
24
24
  def consumer # :nodoc:
25
25
  path = '/v2/oauth/'
26
26
  @consumer ||= OAuth::Consumer.new(Etsy.api_key, Etsy.api_secret, {
27
- :site => "http://#{Etsy.host}",
27
+ :site => "#{Etsy.protocol}://#{Etsy.host}",
28
28
  :request_token_path => "#{path}request_token?scope=#{Etsy.permission_scopes.join('+')}",
29
29
  :access_token_path => "#{path}access_token"
30
30
  })
@@ -76,9 +76,16 @@ module Etsy
76
76
  def put(endpoint)
77
77
  client.put(endpoint)
78
78
  end
79
+
80
+ def delete(endpoint)
81
+ client.delete(endpoint)
82
+ end
79
83
 
80
- def post_multipart(endpoint, params = {})
81
- Net::HTTP.new(Etsy.host).start do |http|
84
+ def post_multipart(endpoint, params = {})
85
+ client = Net::HTTP.new(Etsy.host, Etsy.protocol == "http" ? 80 : 443)
86
+ client.use_ssl = true if Etsy.protocol == "https"
87
+
88
+ client.start do |http|
82
89
  req = Net::HTTP::Post.new(endpoint)
83
90
  add_multipart_data(req, params)
84
91
  add_oauth(req)
@@ -1,3 +1,3 @@
1
1
  module Etsy
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -8,7 +8,7 @@ module Etsy
8
8
  should "be able to construct a client" do
9
9
  Etsy.stubs(:host).returns 'example.com'
10
10
  client = BasicClient.new
11
- Net::HTTP.stubs(:new).with('example.com').returns('client')
11
+ Net::HTTP.stubs(:new).with('example.com', 80).returns('client')
12
12
 
13
13
  client.client.should == 'client'
14
14
  end
@@ -4,6 +4,12 @@ module Etsy
4
4
  class ResponseTest < Test::Unit::TestCase
5
5
 
6
6
  context "An instance of the Response class" do
7
+
8
+ should "be able to return the total" do
9
+ r = Response.new(stub(:body => '{ "count": 42 }'))
10
+
11
+ r.total.should == 42
12
+ end
7
13
 
8
14
  should "be able to decode the JSON data to a hash" do
9
15
  data = '{ "foo":"bar" }'
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Patrick Reagan
@@ -9,11 +10,12 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-06-04 00:00:00.000000000 Z
13
+ date: 2013-08-31 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: json
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
20
  - - ! '>='
19
21
  - !ruby/object:Gem::Version
@@ -21,6 +23,7 @@ dependencies:
21
23
  type: :runtime
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
28
  - - ! '>='
26
29
  - !ruby/object:Gem::Version
@@ -28,6 +31,7 @@ dependencies:
28
31
  - !ruby/object:Gem::Dependency
29
32
  name: oauth
30
33
  requirement: !ruby/object:Gem::Requirement
34
+ none: false
31
35
  requirements:
32
36
  - - ~>
33
37
  - !ruby/object:Gem::Version
@@ -35,6 +39,7 @@ dependencies:
35
39
  type: :runtime
36
40
  prerelease: false
37
41
  version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
38
43
  requirements:
39
44
  - - ~>
40
45
  - !ruby/object:Gem::Version
@@ -42,6 +47,7 @@ dependencies:
42
47
  - !ruby/object:Gem::Dependency
43
48
  name: rake
44
49
  requirement: !ruby/object:Gem::Requirement
50
+ none: false
45
51
  requirements:
46
52
  - - ~>
47
53
  - !ruby/object:Gem::Version
@@ -49,6 +55,7 @@ dependencies:
49
55
  type: :development
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
52
59
  requirements:
53
60
  - - ~>
54
61
  - !ruby/object:Gem::Version
@@ -56,6 +63,7 @@ dependencies:
56
63
  - !ruby/object:Gem::Dependency
57
64
  name: jnunemaker-matchy
58
65
  requirement: !ruby/object:Gem::Requirement
66
+ none: false
59
67
  requirements:
60
68
  - - ~>
61
69
  - !ruby/object:Gem::Version
@@ -63,6 +71,7 @@ dependencies:
63
71
  type: :development
64
72
  prerelease: false
65
73
  version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
66
75
  requirements:
67
76
  - - ~>
68
77
  - !ruby/object:Gem::Version
@@ -70,6 +79,7 @@ dependencies:
70
79
  - !ruby/object:Gem::Dependency
71
80
  name: shoulda
72
81
  requirement: !ruby/object:Gem::Requirement
82
+ none: false
73
83
  requirements:
74
84
  - - ~>
75
85
  - !ruby/object:Gem::Version
@@ -77,6 +87,7 @@ dependencies:
77
87
  type: :development
78
88
  prerelease: false
79
89
  version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
80
91
  requirements:
81
92
  - - ~>
82
93
  - !ruby/object:Gem::Version
@@ -84,6 +95,7 @@ dependencies:
84
95
  - !ruby/object:Gem::Dependency
85
96
  name: mocha
86
97
  requirement: !ruby/object:Gem::Requirement
98
+ none: false
87
99
  requirements:
88
100
  - - ~>
89
101
  - !ruby/object:Gem::Version
@@ -91,6 +103,7 @@ dependencies:
91
103
  type: :development
92
104
  prerelease: false
93
105
  version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
94
107
  requirements:
95
108
  - - ~>
96
109
  - !ruby/object:Gem::Version
@@ -98,17 +111,19 @@ dependencies:
98
111
  - !ruby/object:Gem::Dependency
99
112
  name: minitest
100
113
  requirement: !ruby/object:Gem::Requirement
114
+ none: false
101
115
  requirements:
102
- - - ! '>='
116
+ - - '='
103
117
  - !ruby/object:Gem::Version
104
- version: '0'
118
+ version: 4.7.4
105
119
  type: :development
106
120
  prerelease: false
107
121
  version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
108
123
  requirements:
109
- - - ! '>='
124
+ - - '='
110
125
  - !ruby/object:Gem::Version
111
- version: '0'
126
+ version: 4.7.4
112
127
  description: A friendly Ruby interface to the Etsy API
113
128
  email:
114
129
  - reaganpr@gmail.com
@@ -196,26 +211,27 @@ files:
196
211
  - test/unit/etsy_test.rb
197
212
  homepage: http://github.com/kytrinyx/etsy
198
213
  licenses: []
199
- metadata: {}
200
214
  post_install_message:
201
215
  rdoc_options: []
202
216
  require_paths:
203
217
  - lib
204
218
  required_ruby_version: !ruby/object:Gem::Requirement
219
+ none: false
205
220
  requirements:
206
221
  - - ! '>='
207
222
  - !ruby/object:Gem::Version
208
223
  version: '0'
209
224
  required_rubygems_version: !ruby/object:Gem::Requirement
225
+ none: false
210
226
  requirements:
211
227
  - - ! '>='
212
228
  - !ruby/object:Gem::Version
213
229
  version: '0'
214
230
  requirements: []
215
231
  rubyforge_project:
216
- rubygems_version: 2.0.3
232
+ rubygems_version: 1.8.23
217
233
  signing_key:
218
- specification_version: 4
234
+ specification_version: 3
219
235
  summary: Provides a friendly ruby-like wrapper for the Etsy API
220
236
  test_files:
221
237
  - test/fixtures/address/getUserAddresses.json
@@ -267,4 +283,3 @@ test_files:
267
283
  - test/unit/etsy/user_test.rb
268
284
  - test/unit/etsy/verification_request_test.rb
269
285
  - test/unit/etsy_test.rb
270
- has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTBjNjZiZWJmMWIwZTA2YmMwZjRmZjhiNjYxMmMzZDI0ODBkYzgzNQ==
5
- data.tar.gz: !binary |-
6
- ZjJkMTg0Y2ZhOGM5ODZjMmQ3N2M2MDM1ZTVjOTA0NmI4ZWU0MmU3NQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YjZhNjQwODA1OWI1NjIwNjgzMjViNzMyYzFlMDNmYjE4MjZkYWVlMWUyZDUx
10
- NGEwNTIyMGM0ODc0MWRjZTBkZDY5NmI0ZTE2NDE0NjYwOWYyMTZjNThhMDFm
11
- M2Y2ZDA4NDM4ZmMxYTA5NTAxYjI0MjQ5ZDQ0MmIxMjhkNTg5ZWQ=
12
- data.tar.gz: !binary |-
13
- ZTk3NmZmMTkzOTA5NTQzOWViODBjMjc1ZjljYjM2MDA4YjI3MjhhYzg5ZWRj
14
- YmI0NGVmNWUzZWI5ZWRkYmY0OTk5ZjkzZWYzZmFlZmQ0NzI0NTNjZGU1OWM0
15
- ZjRjOWQ4ZjM0OTBlOWU2ZDgwMTk4MDU0ODAwZDM0Njk1MDM0MmQ=