celery_api 0.0.6 → 0.0.7
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 +58 -22
- data/lib/celery/order.rb +18 -2
- data/lib/celery/product.rb +2 -21
- data/lib/celery/user.rb +3 -2
- data/lib/celery/version.rb +1 -1
- data/spec/celery/order_spec.rb +106 -13
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3240ca40d270eb325b22c8e1f70afa29f49d7254
|
4
|
+
data.tar.gz: 5e78996762c09a83b1d942fbe0e6192c2e84b2e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f99fe013daf03d3b7ce274c7805056bad286ddade05e0f14a5180a99f3f139d922390ea1e8296735545786b9294013ab7d9b0dbe3f9d88ba8e4a7f5baa0d58d4
|
7
|
+
data.tar.gz: 022a2e9d9a2191bb65e7cff5eb5ccb04d17f84ef15a1515a80eec651ef8bf6867b1a66ff2a8765f2ff94fae9087055e6cad3cf511616cb95516a6640204f3147
|
@@ -1,35 +1,71 @@
|
|
1
1
|
module Celery
|
2
2
|
|
3
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
4
|
|
10
|
-
|
11
|
-
|
5
|
+
module ClassMethods
|
6
|
+
def all(args={})
|
7
|
+
response = HTTParty.get("#{endpoint_path}?#{options}")
|
8
|
+
return build_collection(response[endpoint_resource])
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def build_collection(collection)
|
12
|
+
collection.map { |item| self.new(item) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(id)
|
16
|
+
response = HTTParty.get("#{endpoint_path}/#{id}?#{options}")
|
17
|
+
self.new(response[self::ENDPOINT_RESOURCE_SINGULAR])
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(attrs={})
|
21
|
+
response = HTTParty.post(
|
22
|
+
"#{endpoint_path}?#{options}",
|
23
|
+
body: { object_root => attrs }.to_json,
|
24
|
+
headers: { 'Content-Type' => 'application/json' }
|
25
|
+
)
|
26
|
+
|
27
|
+
self.new(response[self::ENDPOINT_RESOURCE_SINGULAR])
|
28
|
+
end
|
16
29
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
options = Celery.parameterize_options
|
21
|
-
response = HTTParty.get("#{endpoint_path}?#{options}")
|
30
|
+
def endpoint_path
|
31
|
+
Celery.endpoint + endpoint_resource
|
32
|
+
end
|
22
33
|
|
23
|
-
|
34
|
+
def endpoint_resource
|
35
|
+
self::ENDPOINT_RESOURCE
|
36
|
+
end
|
37
|
+
|
38
|
+
def object_root
|
39
|
+
self::ENDPOINT_RESOURCE_SINGULAR
|
40
|
+
end
|
41
|
+
|
42
|
+
def options(args={})
|
43
|
+
Celery.parameterize_options(args)
|
44
|
+
end
|
24
45
|
end
|
25
46
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
47
|
+
module InstanceMethods
|
48
|
+
def update(attrs={})
|
49
|
+
update_local_object(attrs)
|
50
|
+
|
51
|
+
response = HTTParty.put(
|
52
|
+
"#{self.class.endpoint_path}/#{self.id}?#{self.class.options}",
|
53
|
+
body: { self.class.object_root => attrs }.to_json,
|
54
|
+
headers: { 'Content-Type' => 'application/json' }
|
55
|
+
)
|
56
|
+
|
57
|
+
return true if response[self.class.object_root]
|
58
|
+
end
|
59
|
+
|
60
|
+
def destroy
|
61
|
+
response = HTTParty.delete("#{self.class.endpoint_path}/#{self.id}?#{self.class.options}")
|
62
|
+
return response['status']
|
63
|
+
end
|
31
64
|
|
32
|
-
|
65
|
+
private
|
66
|
+
def update_local_object(attrs)
|
67
|
+
attrs.each { |key, value| self.send("#{key}=", value) }
|
68
|
+
end
|
33
69
|
end
|
34
70
|
end
|
35
71
|
|
data/lib/celery/order.rb
CHANGED
@@ -2,9 +2,11 @@ module Celery
|
|
2
2
|
|
3
3
|
class Order < Base
|
4
4
|
|
5
|
-
ENDPOINT_RESOURCE
|
5
|
+
ENDPOINT_RESOURCE = "orders"
|
6
|
+
ENDPOINT_RESOURCE_SINGULAR = "order"
|
6
7
|
|
7
|
-
extend Celery::EndpointMethods
|
8
|
+
extend Celery::EndpointMethods::ClassMethods
|
9
|
+
include Celery::EndpointMethods::InstanceMethods
|
8
10
|
|
9
11
|
attr_accessor :id, :status, :name, :image, :slug,
|
10
12
|
:auto_charge, :seller, :buyer, :payment, :products,
|
@@ -36,6 +38,20 @@ module Celery
|
|
36
38
|
@card = Celery::Card.new(card)
|
37
39
|
end
|
38
40
|
|
41
|
+
def cancel
|
42
|
+
response = HTTParty.get(
|
43
|
+
"#{self.class.endpoint_path}/#{self.id}/cancel?#{self.class.options}"
|
44
|
+
)
|
45
|
+
return true if response[self.class.object_root]
|
46
|
+
end
|
47
|
+
|
48
|
+
def charge_deposit
|
49
|
+
response = HTTParty.post(
|
50
|
+
"#{self.class.endpoint_path}/#{self.id}/charge_deposit?#{self.class.options}"
|
51
|
+
)
|
52
|
+
return true if response[self.class.object_root]
|
53
|
+
end
|
54
|
+
|
39
55
|
class << self
|
40
56
|
def decode(encoded_string)
|
41
57
|
decoded_string = Base64.decode64(encoded_string)
|
data/lib/celery/product.rb
CHANGED
@@ -5,7 +5,8 @@ module Celery
|
|
5
5
|
ENDPOINT_RESOURCE = "products"
|
6
6
|
ENDPOINT_RESOURCE_SINGULAR = "product"
|
7
7
|
|
8
|
-
extend Celery::EndpointMethods
|
8
|
+
extend Celery::EndpointMethods::ClassMethods
|
9
|
+
include Celery::EndpointMethods::InstanceMethods
|
9
10
|
|
10
11
|
attr_accessor :id, :_id, :user_id, :slug, :name,
|
11
12
|
:image, :price, :deposit, :shipping,
|
@@ -18,26 +19,6 @@ module Celery
|
|
18
19
|
@_id = id
|
19
20
|
@id = id
|
20
21
|
end
|
21
|
-
|
22
|
-
def update(attrs={})
|
23
|
-
update_local_object(attrs)
|
24
|
-
endpoint_path = Celery.endpoint + "products" + "/" + self.id
|
25
|
-
options = Celery.parameterize_options
|
26
|
-
response = HTTParty.put("#{endpoint_path}?#{options}", body: { product: attrs }.to_json, headers: { 'Content-Type' => 'application/json' })
|
27
|
-
|
28
|
-
return true if response['product']
|
29
|
-
end
|
30
|
-
|
31
|
-
def update_local_object(attrs)
|
32
|
-
attrs.each { |key, value| self.send("#{key}=", value) }
|
33
|
-
end
|
34
|
-
|
35
|
-
def destroy
|
36
|
-
endpoint_path = Celery.endpoint + "products" + "/" + self.id
|
37
|
-
options = Celery.parameterize_options
|
38
|
-
response = HTTParty.delete("#{endpoint_path}?#{options}")
|
39
|
-
return response['status']
|
40
|
-
end
|
41
22
|
end
|
42
23
|
|
43
24
|
end
|
data/lib/celery/user.rb
CHANGED
@@ -7,12 +7,13 @@ module Celery
|
|
7
7
|
:shipping_rates, :tax_rates, :nexus, :stripe, :affirm, :paypal_email,
|
8
8
|
:analytics, :flags, :confirmation_url, :twitter, :facebook, :website,
|
9
9
|
:subscription, :business, :has_affirm, :message_to_buyer, :access_token,
|
10
|
-
:emails, :has_paypalx
|
10
|
+
:emails, :has_paypalx, :confirmation_scripts
|
11
11
|
|
12
12
|
def update(attrs={})
|
13
13
|
update_local_object(attrs)
|
14
14
|
response = perform_request(attrs)
|
15
|
-
|
15
|
+
|
16
|
+
return response['meta']['code'] == 200 ? true : false
|
16
17
|
end
|
17
18
|
|
18
19
|
def perform_request(attrs)
|
data/lib/celery/version.rb
CHANGED
data/spec/celery/order_spec.rb
CHANGED
@@ -18,29 +18,122 @@ describe Celery::Order, 'class methods' do
|
|
18
18
|
order = Celery::Order.decode(celery_encoded_order)
|
19
19
|
expect(order.id).to eq(celery_decoded_order.id)
|
20
20
|
end
|
21
|
+
|
22
|
+
describe '.get' do
|
23
|
+
let!(:attrs) do
|
24
|
+
{
|
25
|
+
seller_id: "5388e71c5d519405004e3c3c",
|
26
|
+
buyer: {
|
27
|
+
"email" => Faker::Internet.email,
|
28
|
+
"name"=> Faker::Name.name,
|
29
|
+
"address"=> {
|
30
|
+
"company_name"=>"",
|
31
|
+
"street"=>"asdfasdf",
|
32
|
+
"street2"=>"",
|
33
|
+
"city"=>"asdfasfa",
|
34
|
+
"state"=>"asdfasdf",
|
35
|
+
"zip"=>"1231234",
|
36
|
+
"country"=>"MX",
|
37
|
+
"phone"=>""
|
38
|
+
},
|
39
|
+
},
|
40
|
+
products: [ { "slug"=>"choco-cake", "name"=>"Chocholate cake", "quantity"=>1 } ]
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
let!(:order) { Celery::Order.create(attrs) }
|
45
|
+
|
46
|
+
it 'returns an order from celery' do
|
47
|
+
order_from_celery = Celery::Order.get(order.id)
|
48
|
+
|
49
|
+
expect(order_from_celery).to be_kind_of Celery::Order
|
50
|
+
expect(order_from_celery.id).to eq(order.id)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '.create' do
|
55
|
+
let!(:attrs) do
|
56
|
+
{
|
57
|
+
seller_id: "5388e71c5d519405004e3c3c",
|
58
|
+
buyer: {
|
59
|
+
"email" => Faker::Internet.email,
|
60
|
+
"name"=> Faker::Name.name,
|
61
|
+
"address"=> {
|
62
|
+
"company_name"=>"",
|
63
|
+
"street"=>"asdfasdf",
|
64
|
+
"street2"=>"",
|
65
|
+
"city"=>"asdfasfa",
|
66
|
+
"state"=>"asdfasdf",
|
67
|
+
"zip"=>"1231234",
|
68
|
+
"country"=>"MX",
|
69
|
+
"phone"=>""
|
70
|
+
},
|
71
|
+
},
|
72
|
+
products: [ { "slug"=>"choco-cake", "name"=>"Chocholate cake", "quantity"=>1 } ]
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'creates the order' do
|
77
|
+
order = Celery::Order.create(attrs)
|
78
|
+
expect(order).to be_kind_of Celery::Order
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
21
82
|
end
|
22
83
|
|
23
84
|
describe Celery::Order, 'instance methods' do
|
24
|
-
let!(:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
85
|
+
let!(:attrs) do
|
86
|
+
{
|
87
|
+
seller_id: "5388e71c5d519405004e3c3c",
|
88
|
+
buyer: {
|
89
|
+
"email" => Faker::Internet.email,
|
90
|
+
"name"=> Faker::Name.name,
|
91
|
+
"address"=> {
|
92
|
+
"company_name"=>"",
|
93
|
+
"street"=>"asdfasdf",
|
94
|
+
"street2"=>"",
|
95
|
+
"city"=>"asdfasfa",
|
96
|
+
"state"=>"asdfasdf",
|
97
|
+
"zip"=>"1231234",
|
98
|
+
"country"=>"MX",
|
99
|
+
"phone"=>""
|
100
|
+
},
|
101
|
+
},
|
102
|
+
products: [ { "slug"=>"choco-cake", "name"=>"Chocholate cake", "quantity"=>1 } ]
|
103
|
+
}
|
29
104
|
end
|
30
105
|
|
31
|
-
|
32
|
-
|
106
|
+
let!(:order) { Celery::Order.create(attrs) }
|
107
|
+
|
108
|
+
it { expect(order.products.first).to be_kind_of Celery::Product }
|
109
|
+
it { expect(order.buyer).to be_kind_of Celery::Buyer }
|
110
|
+
it { expect(order.seller).to be_kind_of Celery::Seller }
|
111
|
+
it { expect(order.tracking).to be_kind_of Celery::Tracking }
|
112
|
+
it { expect(order.card).to be_kind_of Celery::Card }
|
113
|
+
|
114
|
+
describe '#update' do
|
115
|
+
it 'updates the order' do
|
116
|
+
expect(order.update(buyer: { name: Faker::Name.name })).to eq(true)
|
117
|
+
new_order = Celery::Order.get(order.id)
|
118
|
+
expect(new_order.name).to eq(order.name)
|
119
|
+
end
|
33
120
|
end
|
34
121
|
|
35
|
-
|
36
|
-
|
122
|
+
describe '#destroy' do
|
123
|
+
it 'destroys the order' do
|
124
|
+
expect(order.destroy).to eq(true)
|
125
|
+
|
126
|
+
expect { Celery::Order.get(order.id) }.to raise_error
|
127
|
+
end
|
37
128
|
end
|
38
129
|
|
39
|
-
|
40
|
-
|
130
|
+
describe '#cancel' do
|
131
|
+
it 'cancels the order' do
|
132
|
+
expect(order.cancel).to eq(true)
|
133
|
+
end
|
41
134
|
end
|
42
135
|
|
43
|
-
|
44
|
-
|
136
|
+
describe "#charge_deposit" do
|
137
|
+
it 'charges the order\'s deposit'
|
45
138
|
end
|
46
139
|
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.7
|
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-
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -220,12 +220,12 @@ signing_key:
|
|
220
220
|
specification_version: 4
|
221
221
|
summary: Celery API wrapper
|
222
222
|
test_files:
|
223
|
-
- spec/celery/base_spec.rb
|
224
|
-
- spec/celery/buyer_spec.rb
|
225
|
-
- spec/celery/order_spec.rb
|
226
|
-
- spec/celery/product_spec.rb
|
227
|
-
- spec/celery/user_spec.rb
|
228
|
-
- spec/celery_spec.rb
|
229
223
|
- spec/spec_helper.rb
|
230
|
-
- spec/
|
224
|
+
- spec/celery_spec.rb
|
231
225
|
- spec/support/fixtures/celery_encoded_order.txt
|
226
|
+
- spec/support/celery_order_helper.rb
|
227
|
+
- spec/celery/user_spec.rb
|
228
|
+
- spec/celery/buyer_spec.rb
|
229
|
+
- spec/celery/base_spec.rb
|
230
|
+
- spec/celery/product_spec.rb
|
231
|
+
- spec/celery/order_spec.rb
|