celery_api 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecf867d63c591ce22f7fdd6309e97926aa728f08
4
- data.tar.gz: fdea22f584146b9f65e45cc5e0d004241058172e
3
+ metadata.gz: dcabeac6011089d292d5623b4aed00d90ff23f14
4
+ data.tar.gz: 540922b7fd07d0225b8f8fc49b702cf4899f8a9d
5
5
  SHA512:
6
- metadata.gz: 9f93f66f40be67f9f60f1ec9fe804c0d5b3b1e6bddd91d3b07f4eb48d6014df18c1c9600ba3e73ee5fd7a54ea9818120b2bd18fc5a651a1669156d5844e6d8e1
7
- data.tar.gz: a34bcc169cb3666767f533fee3781d9f56efa50adfe5fb0c3ca8410ef195a47fee49358ca8c7451a1dafaeb55d469dd43688acb581ef4ae50ddba1716079fd82
6
+ metadata.gz: 17ca244bd2df8207a59166193412ed1fd5051a9a65b7653dcd62c4869e7194811cea662d6561fd62b32f4fa9348d0a31abc7cde3470fb056ae85ba21ec61d9a7
7
+ data.tar.gz: a4085d41cbc3ab2f1d64b966e09a147937399ac7ebe4cfff69cd459f1c675b1e77c66bd7d1f9f4a2db8b7a86137b6ac073f980407f23d4261e47036b2fcc86d5
@@ -0,0 +1,24 @@
1
+ module Celery
2
+
3
+ module Config
4
+ def access_token=(access_token)
5
+ @access_token = access_token
6
+ end
7
+
8
+ def access_token
9
+ @access_token
10
+ end
11
+
12
+ def endpoint
13
+ @endpoint ||= "https://api.trycelery.com/v1/"
14
+ end
15
+
16
+ def parameterize_options(args={})
17
+ args.merge!(access_token: access_token)
18
+ uri = Addressable::URI.new
19
+ uri.query_values = args
20
+ uri.query
21
+ end
22
+ end
23
+
24
+ end
data/lib/celery/orders.rb CHANGED
@@ -1,15 +1,27 @@
1
1
  module Celery
2
2
 
3
3
  class Orders < Base
4
- attr_accessor :total, :count, :limit,
5
- :offset, :has_more, :orders
6
4
 
7
- def orders=(orders)
8
- @orders = []
9
- orders.each do |order|
10
- @orders << Celery::Order.new(order)
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))
11
22
  end
12
23
  end
24
+
13
25
  end
14
26
 
15
27
  end
@@ -1,13 +1,16 @@
1
1
  module Celery
2
2
 
3
3
  class Products < Base
4
- attr_accessor :total, :count, :limit,
5
- :offset, :has_more, :products
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
6
11
 
7
- def products=(products)
8
- @products = []
9
- products.each do |product|
10
- @products << Celery::Product.new(product)
12
+ def build_products(products)
13
+ products.map { |product| Celery::Product.new(product) }
11
14
  end
12
15
  end
13
16
  end
@@ -0,0 +1,14 @@
1
+ module Celery
2
+
3
+ class User < Base
4
+
5
+ attr_accessor :created, :updated, :created_date, :updated_date,
6
+ :_id, :id, :email, :name, :currency, :webhooks, :notifications,
7
+ :shipping_rates, :tax_rates, :nexus, :stripe, :affirm, :paypal_email,
8
+ :analytics, :flags, :confirmation_url, :twitter, :facebook, :website,
9
+ :subscription, :business, :has_affirm, :message_to_buyer, :access_token,
10
+ :emails, :has_paypalx
11
+
12
+ end
13
+
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Celery
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
data/lib/celery.rb CHANGED
@@ -2,19 +2,19 @@ require 'httparty'
2
2
  require 'addressable/uri'
3
3
 
4
4
  module Celery
5
- autoload :Base, "celery/base"
6
- autoload :Buyer, "celery/buyer"
7
- autoload :Card, "celery/card"
8
- autoload :Order, "celery/order"
9
- autoload :Client, "celery/client"
10
- autoload :Orders, "celery/orders"
11
- autoload :Seller, "celery/seller"
12
- autoload :Address, "celery/address"
13
- autoload :Billing, "celery/billing"
14
- autoload :Product, "celery/product"
15
- autoload :Products, "celery/products"
16
- autoload :Tracking, "celery/tracking"
17
- autoload :ProcessorBase, "celery/processor_base"
18
- autoload :OrdersProcessor, "celery/orders_processor"
19
- autoload :ProductsProcessor, "celery/products_processor"
5
+ autoload :Config, "celery/config"
6
+ extend Celery::Config
7
+
8
+ autoload :User, "celery/user"
9
+ autoload :Base, "celery/base"
10
+ autoload :Card, "celery/card"
11
+ autoload :Buyer, "celery/buyer"
12
+ autoload :Order, "celery/order"
13
+ autoload :Orders, "celery/orders"
14
+ autoload :Seller, "celery/seller"
15
+ autoload :Address, "celery/address"
16
+ autoload :Billing, "celery/billing"
17
+ autoload :Product, "celery/product"
18
+ autoload :Products, "celery/products"
19
+ autoload :Tracking, "celery/tracking"
20
20
  end
@@ -1,21 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Celery::Orders do
4
- let!(:attrs) do
5
- {
6
- "total" => 10,
7
- "count" => 10,
8
- "limit" => 0,
9
- "offset" => 0,
10
- "has_more" => false,
11
- "orders" => [ { "id" => 'foo' } ]
12
- }
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
13
8
  end
14
9
 
15
- let!(:orders) { Celery::Orders.new(attrs) }
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
16
 
17
- it 'returns an instance of the celery order' do
18
- expect(orders.orders).to be_kind_of Array
19
- expect(orders.orders.first).to be_kind_of Celery::Order
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
20
  end
21
21
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Celery::User do
4
+ let!(:attrs) { { "email" => Faker::Internet.email, "name" => Faker::Name.name } }
5
+ let!(:user) { Celery::User.new(attrs) }
6
+
7
+ it 'creates a new instance of user' do
8
+ expect(user).to be_kind_of Celery::User
9
+ end
10
+ end
data/spec/celery_spec.rb CHANGED
@@ -1,5 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Celery do
4
- it { should be_kind_of Module }
4
+ it { should be_kind_of Module }
5
+ it { should respond_to :access_token }
6
+ it { should respond_to :access_token= }
7
+ it { should respond_to :endpoint }
8
+
9
+ it 'returns the endpoint' do
10
+ expect(Celery.endpoint).to eq("https://api.trycelery.com/v1/")
11
+ end
12
+
13
+ it 'assigns the access_token' do
14
+ Celery.access_token = "foo"
15
+ expect(Celery.access_token).to eq("foo")
16
+ end
17
+
18
+ it 'parameterizes a hash of arguments' do
19
+ hash = { limit: 0 }
20
+ uri = Addressable::URI.new
21
+ uri.query_values = hash.merge(access_token: "foo")
22
+ expect(Celery.parameterize_options(hash)).to eq(uri.query)
23
+ end
5
24
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,14 @@
1
+ require "codeclimate-test-reporter"
1
2
  require 'celery_api'
2
3
  require 'faker'
3
4
  require 'pry'
4
5
 
6
+ CodeClimate::TestReporter.start
7
+
5
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
6
9
 
10
+ Celery.access_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1Mzg4ZTcxYzVkNTE5NDA1MDA0ZTNjM2MifQ.Vw1dikATVaAK5YLZFTPOXKpJJexa8T6NiRuE3nh1nAU"
11
+
7
12
  I18n.enforce_available_locales = true
8
13
 
9
14
  RSpec.configure do |config|
@@ -4,6 +4,6 @@ module CeleryOrderHelper
4
4
  end
5
5
 
6
6
  def celery_decoded_order
7
- @decoded_order ||= Celery::OrdersProcessor.new.decode_order(celery_encoded_order)
7
+ @decoded_order ||= Celery::Orders.decode_order(celery_encoded_order)
8
8
  end
9
9
  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.3
4
+ version: 0.0.4
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-14 00:00:00.000000000 Z
11
+ date: 2014-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.6'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rspec-core
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: '3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.2'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: rspec-mocks
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +150,20 @@ dependencies:
122
150
  - - "~>"
123
151
  - !ruby/object:Gem::Version
124
152
  version: '3'
153
+ - !ruby/object:Gem::Dependency
154
+ name: codeclimate-test-reporter
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.3'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.3'
125
167
  description: This is an Ruby library that wraps the Celery data model
126
168
  email:
127
169
  - cavjzz@gmail.com
@@ -135,27 +177,21 @@ files:
135
177
  - lib/celery/billing.rb
136
178
  - lib/celery/buyer.rb
137
179
  - lib/celery/card.rb
138
- - lib/celery/client.rb
180
+ - lib/celery/config.rb
139
181
  - lib/celery/order.rb
140
182
  - lib/celery/orders.rb
141
- - lib/celery/orders_processor.rb
142
- - lib/celery/processor_base.rb
143
183
  - lib/celery/product.rb
144
184
  - lib/celery/products.rb
145
- - lib/celery/products_processor.rb
146
185
  - lib/celery/seller.rb
147
186
  - lib/celery/tracking.rb
187
+ - lib/celery/user.rb
148
188
  - lib/celery/version.rb
149
189
  - lib/celery_api.rb
150
190
  - spec/celery/base_spec.rb
151
191
  - spec/celery/buyer_spec.rb
152
- - spec/celery/client_spec.rb
153
192
  - spec/celery/order_spec.rb
154
- - spec/celery/orders_processor_spec.rb
155
193
  - spec/celery/orders_spec.rb
156
- - spec/celery/processor_base_spec.rb
157
- - spec/celery/products_processor_spec.rb
158
- - spec/celery/products_spec.rb
194
+ - spec/celery/user_spec.rb
159
195
  - spec/celery_spec.rb
160
196
  - spec/spec_helper.rb
161
197
  - spec/support/celery_order_helper.rb
@@ -187,13 +223,9 @@ summary: Celery API wrapper
187
223
  test_files:
188
224
  - spec/celery/base_spec.rb
189
225
  - spec/celery/buyer_spec.rb
190
- - spec/celery/client_spec.rb
191
226
  - spec/celery/order_spec.rb
192
- - spec/celery/orders_processor_spec.rb
193
227
  - spec/celery/orders_spec.rb
194
- - spec/celery/processor_base_spec.rb
195
- - spec/celery/products_processor_spec.rb
196
- - spec/celery/products_spec.rb
228
+ - spec/celery/user_spec.rb
197
229
  - spec/celery_spec.rb
198
230
  - spec/spec_helper.rb
199
231
  - spec/support/celery_order_helper.rb
data/lib/celery/client.rb DELETED
@@ -1,24 +0,0 @@
1
- module Celery
2
-
3
- class Client
4
- attr_accessor :access_token
5
-
6
- def initialize(args={})
7
- @access_token = args[:access_token]
8
- end
9
-
10
- def orders
11
- @orders ||= Celery::OrdersProcessor.new(endpoint, access_token)
12
- end
13
-
14
- def products
15
- @products ||= Celery::ProductsProcessor.new(endpoint, access_token)
16
- end
17
-
18
- private
19
- def endpoint
20
- @endpoint ||= "https://api.trycelery.com/v1/"
21
- end
22
- end
23
-
24
- end
@@ -1,22 +0,0 @@
1
- require 'base64'
2
-
3
- module Celery
4
-
5
- class OrdersProcessor < ProcessorBase
6
- def initialize(endpoint=nil, access_token=nil)
7
- super
8
- @endpoint_path = endpoint + "orders" if endpoint
9
- end
10
-
11
- def all(args={})
12
- response = HTTParty.get("#{endpoint_path}?#{parameterize_options(args)}")
13
- @orders = Celery::Orders.new(response)
14
- end
15
-
16
- def decode_order(encoded_string)
17
- decoded_string = Base64.decode64(encoded_string)
18
- Celery::Order.new(JSON.parse(decoded_string))
19
- end
20
- end
21
-
22
- end
@@ -1,21 +0,0 @@
1
- module Celery
2
-
3
- class ProcessorBase
4
- attr_reader :endpoint_path, :access_token
5
-
6
- def initialize(endpoint=nil, access_token=nil)
7
- @access_token = access_token
8
- end
9
-
10
- private
11
-
12
-
13
- def parameterize_options(args={})
14
- args.merge!(access_token: access_token)
15
- uri = Addressable::URI.new
16
- uri.query_values = args.merge(access_token: access_token)
17
- uri.query
18
- end
19
- end
20
-
21
- end
@@ -1,15 +0,0 @@
1
- module Celery
2
-
3
- class ProductsProcessor < ProcessorBase
4
- def initialize(endpoint=nil, access_token=nil)
5
- super
6
- @endpoint_path = endpoint + "products" if endpoint
7
- end
8
-
9
- def all(args={})
10
- response = HTTParty.get("#{endpoint_path}?#{parameterize_options(args)}")
11
- @orders = Celery::Products.new(response)
12
- end
13
- end
14
-
15
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Celery::Client do
4
- let!(:access_token) { "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1Mzg4ZTcxYzVkNTE5NDA1MDA0ZTNjM2MifQ.Vw1dikATVaAK5YLZFTPOXKpJJexa8T6NiRuE3nh1nAU" }
5
- let!(:client) { Celery::Client.new(access_token: access_token) }
6
-
7
- it 'has the access_token' do
8
- expect(client.access_token).to eq(access_token)
9
- end
10
-
11
- it 'has the API endpoint defined' do
12
- expect(client.send(:endpoint)).to eq("https://api.trycelery.com/v1/")
13
- end
14
-
15
- it 'returns an instance of the orders processor object' do
16
- expect(client.orders).to be_kind_of Celery::OrdersProcessor
17
- end
18
-
19
- it 'returns an instance of the products processor object' do
20
- expect(client.products).to be_kind_of Celery::ProductsProcessor
21
- end
22
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Celery::OrdersProcessor do
4
- let!(:access_token) { "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1Mzg4ZTcxYzVkNTE5NDA1MDA0ZTNjM2MifQ.Vw1dikATVaAK5YLZFTPOXKpJJexa8T6NiRuE3nh1nAU" }
5
- let!(:orders) { Celery::OrdersProcessor.new('https://api.trycelery.com/v1/', access_token) }
6
-
7
- it 'has the path for the endpoint' do
8
- expect(orders.endpoint_path).to eq('https://api.trycelery.com/v1/orders')
9
- end
10
-
11
- it 'receives all orders' do
12
- all_orders = orders.all
13
- expect(all_orders).to be_kind_of Celery::Orders
14
- expect(all_orders.orders).to be_kind_of Array
15
- expect(all_orders.orders.first).to be_kind_of Celery::Order
16
- end
17
-
18
- it 'receives 5 orders' do
19
- expect(orders.all(limit: 5).orders.count).to eq(5)
20
- expect(orders.all(limit: 7).orders.count).to eq(7)
21
- end
22
-
23
- it 'decodes an order from an encoded string' do
24
- order = JSON.parse(Base64.decode64(celery_encoded_order))
25
- celery_order = orders.decode_order(celery_encoded_order)
26
-
27
- expect(celery_order).to be_kind_of Celery::Order
28
- expect(celery_order.id).to eq(order['id'])
29
- end
30
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Celery::ProcessorBase do
4
- let!(:access_token) { "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1Mzg4ZTcxYzVkNTE5NDA1MDA0ZTNjM2MifQ.Vw1dikATVaAK5YLZFTPOXKpJJexa8T6NiRuE3nh1nAU" }
5
- let!(:base_processor) { Celery::ProcessorBase.new('https://api.trycelery.com/v1/', access_token) }
6
-
7
- it 'receives the access token' do
8
- expect(base_processor.access_token).to eq(access_token)
9
- end
10
-
11
- it 'parameterizes a hash of arguments' do
12
- hash = { limit: 0 } ; uri = Addressable::URI.new ; uri.query_values = hash.merge(access_token: access_token)
13
- expect(base_processor.send(:parameterize_options, hash)).to eq(uri.query)
14
- end
15
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Celery::ProductsProcessor do
4
- let!(:access_token) { "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1Mzg4ZTcxYzVkNTE5NDA1MDA0ZTNjM2MifQ.Vw1dikATVaAK5YLZFTPOXKpJJexa8T6NiRuE3nh1nAU" }
5
- let!(:products) { Celery::ProductsProcessor.new('https://api.trycelery.com/v1/', access_token) }
6
-
7
- it 'has the path for the endpoint' do
8
- expect(products.endpoint_path).to eq('https://api.trycelery.com/v1/products')
9
- end
10
-
11
- it 'receives all products' do
12
- all_products = products.all
13
- expect(all_products).to be_kind_of Celery::Products
14
- expect(all_products.products).to be_kind_of Array
15
- expect(all_products.products.first).to be_kind_of Celery::Product
16
- end
17
-
18
- it 'receives 5 products' do
19
- expect(products.all(limit: 1).products.count).to eq(1)
20
- end
21
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Celery::Products do
4
- let!(:attrs) do
5
- {
6
- "total" => 10,
7
- "count" => 10,
8
- "limit" => 0,
9
- "offset" => 0,
10
- "has_more" => false,
11
- "products" => [ { "id" => 'foo' } ]
12
- }
13
- end
14
- let!(:products) { Celery::Products.new(attrs) }
15
-
16
- it 'returns an instance of the celery product' do
17
- expect(products.products).to be_kind_of Array
18
- expect(products.products.first).to be_kind_of Celery::Product
19
- end
20
- end