celery 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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24259f8a1be95e104f3fcc0467eca253f0304acb
4
+ data.tar.gz: ee77758970c43f9848787a0e764427629e9b6017
5
+ SHA512:
6
+ metadata.gz: d61101aebd1da8b573feeba2720ff360a0c0a674ca0e934d5d961e13e21f70d3b5170580e9dfcb4c689e89e3f53ef59241569b001898556efcd45392682d1eb2
7
+ data.tar.gz: 3b60efc37783096140ffe98c2da52986033ed1875b74559141c6d1187bd085aca860c95c2b4337e883acba1661431220e454f9b7991caf39671d1a60e3e04515
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .ruby-version
19
+ .rbenv-gemsets
20
+ .rbenv-vars
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --drb
3
+ --format documentation
4
+ --fail-fast
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in celery.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Brian Getting
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ # Celery
2
+
3
+ A Ruby gem for interacting with the Celery API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'celery'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```ruby
16
+ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```ruby
22
+ gem install celery
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ To get started, you'll need to create a Celery account to get your API access token.
28
+
29
+ ```ruby
30
+ require 'celery'
31
+
32
+ celery = Celery::API.new ('CELERY_API_TOKEN')
33
+ # Also looks in ENV['CELERY_API_TOKEN']
34
+ # celery = Celery::API.new
35
+
36
+ coupons = celery.coupon.all
37
+ # => {"total"=>0, "count"=>0, "limit"=>0, "offset"=>0, "has_more"=>false, "coupons"=>[]}
38
+
39
+ orders = celery.order.all(limit: 100, skip: 2, sort: 'created')
40
+ # => {"total"=>0, "count"=>0, "limit"=>100, "offset"=>2, "has_more"=>false, "orders"=>[]}
41
+
42
+ me = celery.user.me
43
+ me['user']['name']
44
+ # => "Joe Public"
45
+
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'celery/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "celery"
8
+ spec.version = Celery::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ["Brian Getting"]
11
+ spec.email = ["brian@tatem.ae"]
12
+ spec.description = %q{Ruby wrapper for the Celery API}
13
+ spec.summary = %q{Ruby wrapper for the Celery API}
14
+ spec.homepage = "https://github.com/tatemae-consultancy/celery-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'excon', "~> 0.31.0"
23
+ spec.add_dependency 'json', "~> 1.8.1"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rspec", "~> 2.14.1"
27
+ spec.add_development_dependency "rake"
28
+ end
@@ -0,0 +1,186 @@
1
+ require 'rubygems'
2
+ require 'excon'
3
+ require 'json'
4
+
5
+ require "celery/errors"
6
+ require "celery/version"
7
+ require "celery/resources/coupon"
8
+ require "celery/resources/order"
9
+ require "celery/resources/product"
10
+ require "celery/resources/shop"
11
+ require "celery/resources/user"
12
+
13
+ module Celery
14
+ class API
15
+
16
+ attr_accessor :debug, :host, :path, :session, :token
17
+
18
+ def initialize(token=nil, debug=false)
19
+ @host = 'https://api.trycelery.com'
20
+ @path = '/v1'
21
+ @session = Excon.new @host
22
+ @debug = debug
23
+ if not token
24
+ token = ENV['CELERY_API_TOKEN'] if ENV['CELERY_API_TOKEN']
25
+ # TODO: Could put feedback warning here that some methods
26
+ # require an API key.
27
+ end
28
+ @token = token
29
+ end
30
+
31
+ # Make a request to the Celery API
32
+ #
33
+ # @param [Symbol] verb the HTTP request method
34
+ # @param [String] path the HTTP URL path of the request
35
+ # @param [Hash] opts the options to make the request with
36
+ #
37
+ def call(method, path, opts={}, &block) # :nodoc:
38
+ # Ensure the body is JSON
39
+ opts[:body] = JSON.generate(opts[:body]) if opts[:body]
40
+ # Set the headers
41
+ opts[:headers] ||= {}
42
+ opts[:headers].merge!(headers)
43
+ # Set the path
44
+ opts[:path] = "#{@path}/#{path}"
45
+ # Set the access token
46
+ # TODO: Remove and use HTTP Basic Authorization
47
+ opts[:query] ||= {}
48
+ opts[:query].merge!(access_token: @token)
49
+ # Make the request
50
+ req = @session.send(method, opts)
51
+ # Handle the response
52
+ handle_response(req)
53
+ end
54
+
55
+ # Make a GET request
56
+ # @see #call
57
+ #
58
+ def get(path, opts={}, &block) # :nodoc:
59
+ call(:get, path, opts, &block)
60
+ end
61
+
62
+ # Make a POST request
63
+ # @see #call
64
+ #
65
+ def post(path, opts={}, &block) # :nodoc:
66
+ call(:post, path, opts, &block)
67
+ end
68
+
69
+ # Make a PUT request
70
+ # @see #call
71
+ #
72
+ def put(path, opts={}, &block) # :nodoc:
73
+ call(:put, path, opts, &block)
74
+ end
75
+
76
+ # Make a PATCH request
77
+ # @see #call
78
+ #
79
+ def patch(path, opts={}, &block) # :nodoc:
80
+ call(:patch, path, opts, &block)
81
+ end
82
+
83
+ # Make a DELETE request
84
+ # @see #call
85
+ #
86
+ def delete(path, opts={}, &block) # :nodoc:
87
+ call(:delete, path, opts, &block)
88
+ end
89
+
90
+ # Handle the response of a request
91
+ def handle_response(response) # :nodoc:
92
+ case response.status
93
+ when 400
94
+ raise BadRequest.new JSON.parse(response.body)["error"]
95
+ when 401
96
+ raise Unauthorized.new
97
+ when 404
98
+ raise NotFound.new
99
+ when 400...500
100
+ raise ClientError.new JSON.parse(response.body)["error"]
101
+ when 500...600
102
+ raise ServerError.new
103
+ else
104
+ if response.body.is_a?(Integer)
105
+ response.body
106
+ else
107
+ JSON.parse(response.body)
108
+ end
109
+ end
110
+ end
111
+
112
+ # Create an coupons object
113
+ #
114
+ # @return [Celery::Coupons]
115
+ #
116
+ # @example
117
+ #
118
+ # coupons = celery.coupons
119
+ #
120
+ def coupon
121
+ Coupon.new self
122
+ end
123
+
124
+ # Create an orders object
125
+ #
126
+ # @return [Celery::Orders]
127
+ #
128
+ # @example
129
+ #
130
+ # orders = celery.orders
131
+ #
132
+ def order
133
+ Order.new self
134
+ end
135
+
136
+ # Create an products object
137
+ #
138
+ # @return [Celery::Products]
139
+ #
140
+ # @example
141
+ #
142
+ # products = celery.products
143
+ #
144
+ def product
145
+ Product.new self
146
+ end
147
+
148
+ # Create an shop object
149
+ #
150
+ # @return [Celery::Shop]
151
+ #
152
+ # @example
153
+ #
154
+ # shop = celery.shop
155
+ #
156
+ def shop
157
+ Shop.new self
158
+ end
159
+
160
+ # Create an users object
161
+ #
162
+ # @return [Celery::Users]
163
+ #
164
+ # @example
165
+ #
166
+ # users = celery.users
167
+ #
168
+ def user
169
+ User.new self
170
+ end
171
+
172
+ private
173
+
174
+ # Set the request headers
175
+ def headers # :nodoc:
176
+ {
177
+ # TODO: Use HTTP Basic Authorization instead.
178
+ #'Authorization' => "Basic #{Base64.encode64(@token+':X')}",
179
+ 'User-Agent' => "celery-ruby-#{VERSION}",
180
+ 'Content-Type' => 'application/json; charset=utf-8',
181
+ 'Accept' => 'application/json'
182
+ }
183
+ end
184
+
185
+ end
186
+ end
Binary file
@@ -0,0 +1,18 @@
1
+ module Celery
2
+ class Error < StandardError
3
+ end
4
+ class BadRequest < Error
5
+ end
6
+ class ClientError < Error
7
+ end
8
+ class NotFound < Error
9
+ end
10
+ class ServerError < Error
11
+ end
12
+ class TooManyRequests < Error
13
+ end
14
+ class Unauthorized < Error
15
+ end
16
+ class Unavailable < Error
17
+ end
18
+ end
@@ -0,0 +1,136 @@
1
+ module Celery
2
+ class Coupon
3
+ attr_accessor :api
4
+
5
+ def initialize(api)
6
+ @api = api
7
+ end
8
+
9
+ # Returns a list of coupons you have. The coupons are returned
10
+ # in sorted order, with the most recent coupons appearing first.
11
+ #
12
+ # @param [Integer] limit (optional) Limit the number of results.
13
+ # @param [Integer] skip (optional) Skip n results.
14
+ # @param [String] sort (optional) Field name to sort on.
15
+ # @param [String] order (optional) Either `asc` or `desc`.
16
+ #
17
+ # @return [JSON] A JSON object with the following attributes:
18
+ # * total [Integer]
19
+ # * count [Integer]
20
+ # * offset [Integer]
21
+ # * limit [Integer]
22
+ # * has_more [Boolean]
23
+ # * coupons [Array]
24
+ #
25
+ # @see https://www.trycelery.com/developer#list_coupons
26
+ #
27
+ # @example
28
+ #
29
+ # coupons = celery.coupon.all(limit: 25, skip: 2, sort: 'created', order: 'asc')
30
+ # coupons["total"]
31
+ # => 28
32
+ #
33
+ def all(params = {})
34
+ @api.get("coupons", query: params)
35
+ end
36
+
37
+ # Retrieves a coupon that has previously been created.
38
+ #
39
+ # @param [String] coupon_id (required) The identifier of the Coupon to be retrieved.
40
+ #
41
+ # @return [JSON] A Coupon object with the following attributes:
42
+ # * code [String]
43
+ # * type [String]
44
+ # * discount [Integer]
45
+ #
46
+ # @see https://www.trycelery.com/developer#retrieve_coupon
47
+ #
48
+ # @example
49
+ #
50
+ # coupon = celery.coupon.find("123abc")
51
+ # coupon["code"]
52
+ # => "Test Coupon Code"
53
+ #
54
+ def find(coupon_id)
55
+ @api.get("coupons/#{coupon_id}")
56
+ end
57
+
58
+ # Creates a new coupon object.
59
+ #
60
+ # @param [Hash] coupon A hash of coupon attributes.
61
+ # @option coupon [String] code (required) the coupon code.
62
+ # @option coupon [String] type (required) the type of coupon.
63
+ # @option coupon [Integer] discount (required) the amount discounted.
64
+ #
65
+ # @return [JSON] A Coupon object with the following attributes:
66
+ # * code [String]
67
+ # * type [String]
68
+ # * discount [Integer]
69
+ #
70
+ # @see https://www.trycelery.com/developer#create_coupon
71
+ #
72
+ # @example
73
+ #
74
+ # coupon = {
75
+ # code: "New Coupon Code",
76
+ # type: "percent",
77
+ # discount: 10
78
+ # }
79
+ # new_coupon = celery.coupon.new(coupon)
80
+ # new_coupon["code"]
81
+ # => "New Coupon Code"
82
+ #
83
+ def new(coupon)
84
+ @api.post("coupons", body: {coupon: coupon})
85
+ end
86
+
87
+ # Updates an existing coupon object.
88
+ #
89
+ # @param [String] coupon_id (required) The identifier of the Coupon to be updated.
90
+ # @param [Hash] coupon A hash of coupon attributes.
91
+ # @option coupon [String] code (optional) the coupon code.
92
+ # @option coupon [String] type (optional) the type of coupon.
93
+ # @option coupon [Integer] discount (optional) the amount discounted.
94
+ #
95
+ # @return [JSON] A Coupon object with the following attributes:
96
+ # * code [String]
97
+ # * type [String]
98
+ # * discount [Integer]
99
+ #
100
+ # @see https://www.trycelery.com/developer#update_coupon
101
+ #
102
+ # @example
103
+ #
104
+ # updated_coupon = {
105
+ # code: "Another Coupon Code",
106
+ # type: "percent",
107
+ # discount: 15
108
+ # }
109
+ # coupon = celery.coupon.update("123abc", updated_coupon)
110
+ # coupon["code"]
111
+ # => "Another Coupon Code"
112
+ #
113
+ def update(coupon_id, coupon)
114
+ @api.put("coupons/#{coupon_id}", body: {coupon: coupon})
115
+ end
116
+
117
+ # Deletes an existing coupon object.
118
+ #
119
+ # @param [String] coupon_id (required) The identifier of the Coupon to be deleted.
120
+ #
121
+ # @return [JSON] A JSON object with the following attributes:
122
+ # * status [Boolean]
123
+ #
124
+ # @see https://www.trycelery.com/developer#delete_coupon
125
+ #
126
+ # @example
127
+ #
128
+ # result = celery.coupon.destroy("123abc")
129
+ # result["status"]
130
+ # => true
131
+ #
132
+ def destroy(coupon_id)
133
+ @api.delete("coupons/#{coupon_id}")
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,297 @@
1
+ module Celery
2
+ class Order
3
+ attr_accessor :api
4
+
5
+ def initialize(api)
6
+ @api = api
7
+ end
8
+
9
+ # Returns a list of orders you have. The orders are returned
10
+ # in sorted order, with the most recent orders appearing first.
11
+ #
12
+ # @param [Integer] limit (optional) Limit the number of results.
13
+ # @param [Integer] skip (optional) Skip n results.
14
+ # @param [String] sort (optional) Field name to sort on.
15
+ # @param [String] order (optional) Either `asc` or `desc`.
16
+ # @param [String] since (optional) Based on updated. Unix time in milliseconds (ms).
17
+ # @param [String] until (optional) Based on updated. Unix time in milliseconds (ms).
18
+ # @param [String] status (optional) Once of `paid`, `paid_balance`, `paid_deposit`, `refunded`, `shipped`.
19
+ #
20
+ # @return [JSON] A JSON object with the following attributes:
21
+ # * total [Integer]
22
+ # * count [Integer]
23
+ # * offset [Integer]
24
+ # * limit [Integer]
25
+ # * has_more [Boolean]
26
+ # * orders [Array]
27
+ #
28
+ # @see https://www.trycelery.com/developer#list_orders
29
+ #
30
+ # @example
31
+ #
32
+ # orders = celery.order.all(limit: 25, skip: 2, sort: 'created', order: 'asc')
33
+ # orders["total"]
34
+ # => 158
35
+ #
36
+ def all(params = {})
37
+ @api.get("orders", query: params)
38
+ end
39
+
40
+ # Returns a list of `paid` orders.
41
+ # @see #all
42
+ #
43
+ # @example
44
+ #
45
+ # paid = celery.order.paid(limit: 25, skip: 2, sort: 'created', order: 'asc')
46
+ # paid["total"]
47
+ # => 5
48
+ #
49
+ def paid(params = {})
50
+ params[:status] = 'paid'
51
+ all(params)
52
+ end
53
+
54
+ # Returns a list of `paid_balance` orders.
55
+ # @see #all
56
+ #
57
+ # @example
58
+ #
59
+ # paid = celery.order.paid_balance(limit: 25, skip: 2, sort: 'created', order: 'asc')
60
+ # paid["total"]
61
+ # => 5
62
+ #
63
+ def paid_balance(params = {})
64
+ params[:status] = 'paid_balance'
65
+ all(params)
66
+ end
67
+
68
+ # Returns a list of `paid_deposit` orders.
69
+ # @see #all
70
+ #
71
+ # @example
72
+ #
73
+ # paid = celery.order.paid_deposit(limit: 25, skip: 2, sort: 'created', order: 'asc')
74
+ # paid["total"]
75
+ # => 5
76
+ #
77
+ def paid_deposit(params = {})
78
+ params[:status] = 'paid_deposit'
79
+ all(params)
80
+ end
81
+
82
+ # Returns a list of `refunded` orders.
83
+ # @see #all
84
+ #
85
+ # @example
86
+ #
87
+ # paid = celery.order.refunded(limit: 25, skip: 2, sort: 'created', order: 'asc')
88
+ # paid["total"]
89
+ # => 5
90
+ #
91
+ def refunded(params = {})
92
+ params[:status] = 'refunded'
93
+ all(params)
94
+ end
95
+
96
+ # Returns a list of `shipped` orders.
97
+ # @see #all
98
+ #
99
+ # @example
100
+ #
101
+ # paid = celery.order.shipped(limit: 25, skip: 2, sort: 'created', order: 'asc')
102
+ # paid["total"]
103
+ # => 5
104
+ #
105
+ def shipped(params = {})
106
+ params[:status] = 'shipped'
107
+ all(params)
108
+ end
109
+
110
+ # Retrieves an order that has previously been created.
111
+ #
112
+ # @param [String] order_id (required) The identifier of the Order to be retrieved.
113
+ #
114
+ # @return [JSON] An Order object.
115
+ #
116
+ # @see https://www.trycelery.com/developer#retrieve_order
117
+ #
118
+ # @example
119
+ #
120
+ # order = celery.order.find("123abc")
121
+ # order["_id"]
122
+ # => "51ad40901a7e9b0200000006"
123
+ #
124
+ def find(order_id)
125
+ @api.get("orders/#{order_id}")
126
+ end
127
+
128
+ # Creates a new order object.
129
+ #
130
+ # @param [Hash] order A hash of order attributes.
131
+ #
132
+ # @return [JSON] An Order object.
133
+ #
134
+ # @see https://www.trycelery.com/developer#create_order
135
+ #
136
+ # @example
137
+ #
138
+ # order = {
139
+ # seller_id: "123abc456",
140
+ # buyer: {
141
+ # email: "joe@public.com",
142
+ # ...
143
+ # },
144
+ # ...
145
+ # }
146
+ # new_order = celery.order.new(order)
147
+ # new_order["_id"]
148
+ # => "51ad40901a7e9b0200000006"
149
+ #
150
+ def new(order)
151
+ @api.post("orders", body: {order: order})
152
+ end
153
+
154
+ # Updates an existing order object.
155
+ #
156
+ # @param [String] order_id (required) The identifier of the Order to be updated.
157
+ # @param [Hash] order A hash of order attributes.
158
+ #
159
+ # @return [JSON] An Order object.
160
+ #
161
+ # @see https://www.trycelery.com/developer#update_order
162
+ #
163
+ # @example
164
+ #
165
+ # updated_order = {
166
+ # status: "refunded"
167
+ # }
168
+ # order = celery.order.update("123abc", updated_order)
169
+ # order["status"]
170
+ # => "refunded"
171
+ #
172
+ def update(order_id, order)
173
+ @api.put("orders/#{order_id}", body: {order: order})
174
+ end
175
+
176
+ # Deletes an existing order object.
177
+ #
178
+ # @param [String] order_id (required) The identifier of the Order to be deleted.
179
+ #
180
+ # @return [JSON] A JSON object with the following attributes:
181
+ # * status [Boolean]
182
+ #
183
+ # @see https://www.trycelery.com/developer#delete_order
184
+ #
185
+ # @example
186
+ #
187
+ # result = celery.order.destroy("123abc")
188
+ # result["status"]
189
+ # => true
190
+ #
191
+ def destroy(order_id)
192
+ @api.delete("orders/#{order_id}")
193
+ end
194
+
195
+ # TODO: There is no way that this is a get request!
196
+ # TODO: Is "cancelled" and order status?
197
+ # Cancels an order.
198
+ #
199
+ # @param [String] order_id (required) The identifier of the Order to be cancelled.
200
+ #
201
+ # @return [JSON] An Order object.
202
+ #
203
+ # @see https://www.trycelery.com/developer#cancel_order
204
+ #
205
+ # @example
206
+ #
207
+ # cancelled_order = celery.order.cancel("123abc")
208
+ # cancelled_order["status"]
209
+ # => cancelled
210
+ #
211
+ def cancel(order_id)
212
+ @api.get("orders/#{order_id}/cancel")
213
+ end
214
+
215
+ # Charges deposit.
216
+ #
217
+ # @param [String] order_id (required) The identifier of the Order to charge.
218
+ #
219
+ # @return [JSON] An Order object.
220
+ #
221
+ # @see https://www.trycelery.com/developer#charge_order_deposit
222
+ #
223
+ # @example
224
+ #
225
+ # charge = celery.order.charge_deposit("123abc")
226
+ #
227
+ def charge_deposit(order_id)
228
+ @api.post("orders/#{order_id}/charge_deposit")
229
+ end
230
+
231
+ # Charges balance.
232
+ #
233
+ # @param [String] order_id (required) The identifier of the Order to charge.
234
+ #
235
+ # @return [JSON] An Order object.
236
+ #
237
+ # @see https://www.trycelery.com/developer#charge_order_balance
238
+ #
239
+ # @example
240
+ #
241
+ # charge = celery.order.charge_balance("123abc")
242
+ #
243
+ def charge_balance(order_id)
244
+ @api.post("orders/#{order_id}/charge_balance")
245
+ end
246
+
247
+ # Refunds deposit.
248
+ #
249
+ # @param [String] order_id (required) The identifier of the Order to charge.
250
+ #
251
+ # @return [JSON] An Order object.
252
+ #
253
+ # @see https://www.trycelery.com/developer#refund_order_deposit
254
+ #
255
+ # @example
256
+ #
257
+ # refund = celery.order.refund_deposit("123abc")
258
+ #
259
+ def refund_deposit(order_id)
260
+ @api.post("orders/#{order_id}/refund_deposit")
261
+ end
262
+
263
+ # Refunds balance.
264
+ #
265
+ # @param [String] order_id (required) The identifier of the Order to charge.
266
+ #
267
+ # @return [JSON] An Order object.
268
+ #
269
+ # @see https://www.trycelery.com/developer#refund_order_balance
270
+ #
271
+ # @example
272
+ #
273
+ # refund = celery.order.refund_balance("123abc")
274
+ #
275
+ def refund_balance(order_id)
276
+ @api.post("orders/#{order_id}/refund_balance")
277
+ end
278
+
279
+ # TODO: There is no way that this is a get request!
280
+ # TODO: Is "cancelled" and order status?
281
+ # Changes order status to `shipped `.
282
+ #
283
+ # @param [String] order_id (required) The identifier of the Order to ship.
284
+ #
285
+ # @return [JSON] An Order object.
286
+ #
287
+ # @see https://www.trycelery.com/developer#ship_order
288
+ #
289
+ # @example
290
+ #
291
+ # refund = celery.order.ship("123abc")
292
+ #
293
+ def ship(order_id)
294
+ @api.get("orders/#{order_id}/ship")
295
+ end
296
+ end
297
+ end
@@ -0,0 +1,121 @@
1
+ module Celery
2
+ class Product
3
+ attr_accessor :api
4
+
5
+ def initialize(api)
6
+ @api = api
7
+ end
8
+
9
+ # Returns a list of products you have.
10
+ #
11
+ # @param [Integer] limit (optional) Limit the number of results.
12
+ # @param [Integer] skip (optional) Skip n results.
13
+ # @param [String] sort (optional) Field name to sort on.
14
+ # @param [String] order (optional) Either `asc` or `desc`.
15
+ #
16
+ # @return [JSON] A JSON object with the following attributes:
17
+ # * total [Integer]
18
+ # * count [Integer]
19
+ # * offset [Integer]
20
+ # * limit [Integer]
21
+ # * has_more [Boolean]
22
+ # * products [Array]
23
+ #
24
+ # @see https://www.trycelery.com/developer#list_products
25
+ #
26
+ # @example
27
+ #
28
+ # products = celery.product.all(limit: 25, skip: 2, sort: 'created', order: 'asc')
29
+ # products.total
30
+ # => 28
31
+ #
32
+ def all(params = {})
33
+ @api.get("products", query: params)
34
+ end
35
+
36
+ # Retrieves a product that has previously been created.
37
+ #
38
+ # @param [String] product_id (required) The identifier of the Product to be retrieved.
39
+ #
40
+ # @return [JSON] A Product object.
41
+ #
42
+ # @see https://www.trycelery.com/developer#retrieve_product
43
+ #
44
+ # @example
45
+ #
46
+ # product = celery.product.find("123abc")
47
+ # product["slug"]
48
+ # => "test-product"
49
+ #
50
+ def find(product_id)
51
+ @api.get("products/#{product_id}")
52
+ end
53
+
54
+ # Creates a new product object.
55
+ #
56
+ # @param [Hash] product A hash of product attributes.
57
+ # @option product [String] name (optional) the product name.
58
+ # @option product [Integer] price (optional) in cents.
59
+ # @option product [Integer] deposit (optional) in cents.
60
+ # @option product [Array] options (optional)
61
+ #
62
+ # @return [JSON] A Product object.
63
+ #
64
+ # @see https://www.trycelery.com/developer#create_product
65
+ #
66
+ # @example
67
+ #
68
+ # product = {
69
+ # name: "New Product",
70
+ # price: 1999,
71
+ # }
72
+ # new_product = celery.product.new(product)
73
+ # new_product["name"]
74
+ # => "New Product"
75
+ #
76
+ def new(product)
77
+ @api.post("products", body: {product: product})
78
+ end
79
+
80
+ # Updates an existing product object.
81
+ #
82
+ # @param [String] product_id (required) The identifier of the Product to be updated.
83
+ # @param [Hash] product A hash of product attributes.
84
+ #
85
+ # @return [JSON] A Product object.
86
+ #
87
+ # @see https://www.trycelery.com/developer#update_product
88
+ #
89
+ # @example
90
+ #
91
+ # product = {
92
+ # name: "New Name"
93
+ # }
94
+ # updated = celery.product.update("123abc", product)
95
+ # updated["name"]
96
+ # => "New Name"
97
+ #
98
+ def update(product_id, product)
99
+ @api.put("products/#{product_id}", body: {product: product})
100
+ end
101
+
102
+ # Deletes an existing product object.
103
+ #
104
+ # @param [String] product_id (required) The identifier of the Product to be deleted.
105
+ #
106
+ # @return [JSON] A JSON object with the following attributes:
107
+ # * status [Boolean]
108
+ #
109
+ # @see https://www.trycelery.com/developer#delete_product
110
+ #
111
+ # @example
112
+ #
113
+ # result = celery.product.destroy("123abc")
114
+ # result["status"]
115
+ # => true
116
+ #
117
+ def destroy(product_id)
118
+ @api.delete("products/#{product_id}")
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,100 @@
1
+ module Celery
2
+ class Shop
3
+ attr_accessor :api
4
+
5
+ def initialize(api)
6
+ @api = api
7
+ end
8
+
9
+ # Retrieves the public details of a Product or Collection that has
10
+ # previously been created.
11
+ #
12
+ # @param [String] slug (required) The identifier of the Product or Collection to be retrieved.
13
+ #
14
+ # @return [JSON] A Product or Collection object
15
+ #
16
+ # @see https://www.trycelery.com/developer#retrieve_shop
17
+ #
18
+ # @example
19
+ #
20
+ # shop = celery.shop.find("product-slug")
21
+ # => { "product": { "_id": "123abc", ... } }
22
+ #
23
+ def find(slug)
24
+ @api.get("shop/#{slug}")
25
+ end
26
+
27
+ # Returns whether a product slug is being used.
28
+ #
29
+ # @param [String] slug (required) The identifier of the slug to check.
30
+ #
31
+ # @return [JSON] A JSON object with the following attributes:
32
+ # * slugify [Boolean]
33
+ #
34
+ # @see https://www.trycelery.com/developer#check_slug
35
+ #
36
+ # @example
37
+ #
38
+ # check = celery.shop.check("test-slug")
39
+ # check["slugify"]
40
+ # => false
41
+ #
42
+ def check(slug)
43
+ @api.get("slugify", query: {slug: slug})
44
+ end
45
+
46
+ # TODO: This seems like a duplicate of Order#new.
47
+ # Checkout with credit card and creates a new order object.
48
+ #
49
+ # @param [Hash] order A hash of order attributes.
50
+ #
51
+ # @return [JSON] An Order object.
52
+ #
53
+ # @see https://www.trycelery.com/developer#checkout
54
+ #
55
+ # @example
56
+ #
57
+ # order = {
58
+ # seller_id: "123abc456",
59
+ # buyer: {
60
+ # email: "joe@public.com",
61
+ # ...
62
+ # },
63
+ # ...
64
+ # }
65
+ # checkout = celery.shop.checkout(order)
66
+ # checkout["_id"]
67
+ # => "51ad40901a7e9b0200000006"
68
+ #
69
+ def checkout(order)
70
+ @api.post("checkout", body: {order: order})
71
+ end
72
+
73
+ # TODO: This seems like a duplicate of Order#new.
74
+ # Checkout with PayPal and creates a new order object with PayPal.
75
+ #
76
+ # @param [Hash] order A hash of order attributes.
77
+ #
78
+ # @return [JSON] An Order object.
79
+ #
80
+ # @see https://www.trycelery.com/developer#checkout_paypal
81
+ #
82
+ # @example
83
+ #
84
+ # order = {
85
+ # seller_id: "123abc456",
86
+ # buyer: {
87
+ # email: "joe@public.com",
88
+ # ...
89
+ # },
90
+ # ...
91
+ # }
92
+ # checkout = celery.shop.checkout_paypal(order)
93
+ # checkout["_id"]
94
+ # => "51ad40901a7e9b0200000006"
95
+ #
96
+ def checkout_paypal(order)
97
+ @api.post("checkout/paypal", body: {order: order})
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,44 @@
1
+ module Celery
2
+ class User
3
+ attr_accessor :api
4
+
5
+ def initialize(api)
6
+ @api = api
7
+ end
8
+
9
+ # Retrieves seller information about yourself.
10
+ #
11
+ # @return [JSON] A User object.
12
+ #
13
+ # @see https://www.trycelery.com/developer#retrieve_yourself
14
+ #
15
+ # @example
16
+ #
17
+ # profile = celery.user.me
18
+ # profile["email"]
19
+ # => "joe@public.com"
20
+ #
21
+ def me
22
+ @api.get("users/me")
23
+ end
24
+
25
+ # TODO: Need to get the arguments for this method.
26
+ # Updates seller information about yourself.
27
+ #
28
+ # @param [Hash] user A hash of user attributes.
29
+ #
30
+ # @return [JSON] A User object.
31
+ #
32
+ # @see https://www.trycelery.com/developer#update_yourself
33
+ #
34
+ # @example
35
+ #
36
+ # profile = celery.user.update(email: 'john@public.com')
37
+ # profile["email"]
38
+ # => "john@public.com"
39
+ #
40
+ def update(user)
41
+ @api.put("users/me", body: {user: user})
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Celery
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1 @@
1
+ require 'celery'
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: celery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Brian Getting
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: excon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.31.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.31.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby wrapper for the Celery API
84
+ email:
85
+ - brian@tatem.ae
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - celery.gemspec
97
+ - lib/celery.rb
98
+ - lib/celery/.DS_Store
99
+ - lib/celery/errors.rb
100
+ - lib/celery/resources/coupon.rb
101
+ - lib/celery/resources/order.rb
102
+ - lib/celery/resources/product.rb
103
+ - lib/celery/resources/shop.rb
104
+ - lib/celery/resources/user.rb
105
+ - lib/celery/version.rb
106
+ - rails/init.rb
107
+ homepage: https://github.com/tatemae-consultancy/celery-ruby
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.0.14
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Ruby wrapper for the Celery API
131
+ test_files: []