celery_api 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/celery/endpoint_methods.rb +18 -0
- data/lib/celery/order.rb +12 -0
- data/lib/celery/product.rb +5 -0
- data/lib/celery/user.rb +27 -0
- data/lib/celery/version.rb +1 -1
- data/lib/celery.rb +1 -2
- data/spec/celery/base_spec.rb +3 -3
- data/spec/celery/order_spec.rb +21 -1
- data/spec/celery/product_spec.rb +16 -0
- data/spec/celery/user_spec.rb +21 -2
- data/spec/support/celery_order_helper.rb +1 -1
- metadata +6 -7
- data/lib/celery/orders.rb +0 -27
- data/lib/celery/products.rb +0 -18
- data/spec/celery/orders_spec.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b993b4bbeabfb0ea78df6e5f172d6b201b3672bf
|
4
|
+
data.tar.gz: 69a75b093c226864dce5a23c0abfb57a9cd3a343
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f6a1556332b0d854ef9d77b9d0eee7d3c538197bf8bf689a7503bd87dcb13a1e3eec50d62a3e26d51dd0e346388b9cc1e835eaf8690ab68ffc4d682908a9422
|
7
|
+
data.tar.gz: a527b8fa9049885d67dc2087147abce34cbe14b5ac810b8eb35a300813a7fec0ec4297b6eaf6faba2571e35fcf5c05414485cb1040b0d6b4bbe19a2a357bc674
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Celery
|
2
|
+
|
3
|
+
module EndpointMethods
|
4
|
+
def all(args={})
|
5
|
+
endpoint_resource = self::ENDPOINT_RESOURCE
|
6
|
+
endpoint_path = Celery.endpoint + endpoint_resource
|
7
|
+
options = Celery.parameterize_options(args)
|
8
|
+
response = HTTParty.get("#{endpoint_path}?#{options}")
|
9
|
+
|
10
|
+
return build_collection(response[endpoint_resource])
|
11
|
+
end
|
12
|
+
|
13
|
+
def build_collection(collection)
|
14
|
+
collection.map { |item| self.new(item) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/celery/order.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
module Celery
|
2
2
|
|
3
3
|
class Order < Base
|
4
|
+
|
5
|
+
ENDPOINT_RESOURCE = "orders"
|
6
|
+
|
7
|
+
extend Celery::EndpointMethods
|
8
|
+
|
4
9
|
attr_accessor :id, :status, :name, :image, :slug,
|
5
10
|
:auto_charge, :seller, :buyer, :payment, :products,
|
6
11
|
:coupon, :subtotal, :total, :deposit, :balance, :discount,
|
@@ -30,6 +35,13 @@ module Celery
|
|
30
35
|
def card=(card)
|
31
36
|
@card = Celery::Card.new(card)
|
32
37
|
end
|
38
|
+
|
39
|
+
class << self
|
40
|
+
def decode(encoded_string)
|
41
|
+
decoded_string = Base64.decode64(encoded_string)
|
42
|
+
Celery::Order.new(JSON.parse(decoded_string))
|
43
|
+
end
|
44
|
+
end
|
33
45
|
end
|
34
46
|
|
35
47
|
end
|
data/lib/celery/product.rb
CHANGED
data/lib/celery/user.rb
CHANGED
@@ -9,6 +9,33 @@ module Celery
|
|
9
9
|
:subscription, :business, :has_affirm, :message_to_buyer, :access_token,
|
10
10
|
:emails, :has_paypalx
|
11
11
|
|
12
|
+
def update(attrs={})
|
13
|
+
update_local_object(attrs)
|
14
|
+
response = perform_request(attrs)
|
15
|
+
return true if response['meta']['code'] == 200
|
16
|
+
end
|
17
|
+
|
18
|
+
def perform_request(attrs)
|
19
|
+
HTTParty.put(
|
20
|
+
Celery.endpoint + "users/me?" + Celery.parameterize_options,
|
21
|
+
body: attrs.to_json,
|
22
|
+
headers: { 'Content-Type' => 'application/json' }
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_local_object(attrs)
|
27
|
+
attrs.each { |key, value| self.send("#{key}=", value) }
|
28
|
+
end
|
29
|
+
|
30
|
+
class << self
|
31
|
+
def me
|
32
|
+
query_string = Celery.endpoint + "users/me?"
|
33
|
+
query_string += Celery.parameterize_options
|
34
|
+
response = HTTParty.get(query_string)
|
35
|
+
|
36
|
+
self.new(response['data'])
|
37
|
+
end
|
38
|
+
end
|
12
39
|
end
|
13
40
|
|
14
41
|
end
|
data/lib/celery/version.rb
CHANGED
data/lib/celery.rb
CHANGED
@@ -10,11 +10,10 @@ module Celery
|
|
10
10
|
autoload :Card, "celery/card"
|
11
11
|
autoload :Buyer, "celery/buyer"
|
12
12
|
autoload :Order, "celery/order"
|
13
|
-
autoload :Orders, "celery/orders"
|
14
13
|
autoload :Seller, "celery/seller"
|
15
14
|
autoload :Address, "celery/address"
|
16
15
|
autoload :Billing, "celery/billing"
|
17
16
|
autoload :Product, "celery/product"
|
18
|
-
autoload :Products, "celery/products"
|
19
17
|
autoload :Tracking, "celery/tracking"
|
18
|
+
autoload :EndpointMethods, "celery/endpoint_methods"
|
20
19
|
end
|
data/spec/celery/base_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Celery::Base do
|
4
|
-
Celery::Base
|
4
|
+
class Foo < Celery::Base
|
5
5
|
attr_accessor :foo
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'calls the accessor' do
|
9
|
-
expect_any_instance_of(
|
10
|
-
|
9
|
+
expect_any_instance_of(Foo).to receive(:foo=)
|
10
|
+
Foo.new(foo: 'foo')
|
11
11
|
end
|
12
12
|
end
|
data/spec/celery/order_spec.rb
CHANGED
@@ -1,6 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Celery::Order do
|
3
|
+
describe Celery::Order, 'class methods' do
|
4
|
+
it 'returns all the orders from the endpoint' do
|
5
|
+
orders = Celery::Order.all
|
6
|
+
expect(orders).to be_kind_of Array
|
7
|
+
expect(orders.first).to be_kind_of Celery::Order
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'builds the orders based on the array' do
|
11
|
+
orders = [{ "id" => "1234" }]
|
12
|
+
orders = Celery::Order.build_collection(orders)
|
13
|
+
expect(orders.first).to be_kind_of Celery::Order
|
14
|
+
expect(orders.first.id).to eq("1234")
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'decodes the order' do
|
18
|
+
order = Celery::Order.decode(celery_encoded_order)
|
19
|
+
expect(order.id).to eq(celery_decoded_order.id)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Celery::Order, 'instance methods' do
|
4
24
|
let!(:order) { celery_decoded_order }
|
5
25
|
|
6
26
|
it 'returns an instance of the celery product' do
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Celery::Product do
|
4
|
+
it 'returns all the products from the endpoint' do
|
5
|
+
products = Celery::Product.all
|
6
|
+
expect(products).to be_kind_of Array
|
7
|
+
expect(products.first).to be_kind_of Celery::Product
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'builds the products based on the array' do
|
11
|
+
products = [{ "id" => "1234" }]
|
12
|
+
products = Celery::Product.build_collection(products)
|
13
|
+
expect(products.first).to be_kind_of Celery::Product
|
14
|
+
expect(products.first.id).to eq("1234")
|
15
|
+
end
|
16
|
+
end
|
data/spec/celery/user_spec.rb
CHANGED
@@ -1,10 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Celery::User do
|
3
|
+
describe Celery::User, 'class methods' do
|
4
|
+
it 'gets the user' do
|
5
|
+
expect(Celery::User.me).to be_kind_of Celery::User
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Celery::User, 'instance methods' do
|
4
10
|
let!(:attrs) { { "email" => Faker::Internet.email, "name" => Faker::Name.name } }
|
5
|
-
let!(:user) { Celery::User.
|
11
|
+
let!(:user) { Celery::User.me }
|
6
12
|
|
7
13
|
it 'creates a new instance of user' do
|
8
14
|
expect(user).to be_kind_of Celery::User
|
9
15
|
end
|
16
|
+
|
17
|
+
context 'Update' do
|
18
|
+
it 'performs the action' do
|
19
|
+
expect(user.update(name: 'Antonio')).to eq(true)
|
20
|
+
expect(user.name).to eq('Antonio')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "does not perform the action if there's no product present" do
|
24
|
+
expect{
|
25
|
+
user.update(foo: 'foo')
|
26
|
+
}.to raise_error NoMethodError
|
27
|
+
end
|
28
|
+
end
|
10
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celery_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antonio Chavez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -178,10 +178,9 @@ files:
|
|
178
178
|
- lib/celery/buyer.rb
|
179
179
|
- lib/celery/card.rb
|
180
180
|
- lib/celery/config.rb
|
181
|
+
- lib/celery/endpoint_methods.rb
|
181
182
|
- lib/celery/order.rb
|
182
|
-
- lib/celery/orders.rb
|
183
183
|
- lib/celery/product.rb
|
184
|
-
- lib/celery/products.rb
|
185
184
|
- lib/celery/seller.rb
|
186
185
|
- lib/celery/tracking.rb
|
187
186
|
- lib/celery/user.rb
|
@@ -190,13 +189,13 @@ files:
|
|
190
189
|
- spec/celery/base_spec.rb
|
191
190
|
- spec/celery/buyer_spec.rb
|
192
191
|
- spec/celery/order_spec.rb
|
193
|
-
- spec/celery/
|
192
|
+
- spec/celery/product_spec.rb
|
194
193
|
- spec/celery/user_spec.rb
|
195
194
|
- spec/celery_spec.rb
|
196
195
|
- spec/spec_helper.rb
|
197
196
|
- spec/support/celery_order_helper.rb
|
198
197
|
- spec/support/fixtures/celery_encoded_order.txt
|
199
|
-
homepage: https://github.com/
|
198
|
+
homepage: https://github.com/tangosource/celery_api
|
200
199
|
licenses:
|
201
200
|
- MIT
|
202
201
|
metadata: {}
|
@@ -224,7 +223,7 @@ test_files:
|
|
224
223
|
- spec/celery/base_spec.rb
|
225
224
|
- spec/celery/buyer_spec.rb
|
226
225
|
- spec/celery/order_spec.rb
|
227
|
-
- spec/celery/
|
226
|
+
- spec/celery/product_spec.rb
|
228
227
|
- spec/celery/user_spec.rb
|
229
228
|
- spec/celery_spec.rb
|
230
229
|
- spec/spec_helper.rb
|
data/lib/celery/orders.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Celery
|
2
|
-
|
3
|
-
class Orders < Base
|
4
|
-
|
5
|
-
class << self
|
6
|
-
def all(args={})
|
7
|
-
endpoint_path = Celery.endpoint + "orders"
|
8
|
-
options = Celery.parameterize_options(args)
|
9
|
-
response = HTTParty.get("#{endpoint_path}?#{options}")
|
10
|
-
return build_orders(response['orders'])
|
11
|
-
end
|
12
|
-
|
13
|
-
def build_orders(orders)
|
14
|
-
orders.map do |order|
|
15
|
-
Celery::Order.new(order)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def decode_order(encoded_string)
|
20
|
-
decoded_string = Base64.decode64(encoded_string)
|
21
|
-
Celery::Order.new(JSON.parse(decoded_string))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
data/lib/celery/products.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Celery
|
2
|
-
|
3
|
-
class Products < Base
|
4
|
-
class << self
|
5
|
-
def all(args={})
|
6
|
-
endpoint_path = Celery.endpoint + "products"
|
7
|
-
options = Celery.parameterize_options(args)
|
8
|
-
response = HTTParty.get("#{endpoint_path}?#{options}")
|
9
|
-
return build_products(response['products'])
|
10
|
-
end
|
11
|
-
|
12
|
-
def build_products(products)
|
13
|
-
products.map { |product| Celery::Product.new(product) }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
data/spec/celery/orders_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Celery::Orders do
|
4
|
-
it 'returns all the orders from the endpoint' do
|
5
|
-
orders = Celery::Orders.all
|
6
|
-
expect(orders).to be_kind_of Array
|
7
|
-
expect(orders.first).to be_kind_of Celery::Order
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'builds the orders based on the array' do
|
11
|
-
orders = [{ "id" => "1234" }]
|
12
|
-
orders = Celery::Orders.build_orders(orders)
|
13
|
-
expect(orders.first).to be_kind_of Celery::Order
|
14
|
-
expect(orders.first.id).to eq("1234")
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'decodes the order' do
|
18
|
-
order = Celery::Orders.decode_order(celery_encoded_order)
|
19
|
-
expect(order.id).to eq(celery_decoded_order.id)
|
20
|
-
end
|
21
|
-
end
|