xpost 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/TODO.md +28 -1
  4. data/lib/.DS_Store +0 -0
  5. data/lib/xpost.rb +8 -6
  6. data/lib/xpost/.DS_Store +0 -0
  7. data/lib/xpost/address.rb +77 -0
  8. data/lib/xpost/authentication.rb +5 -0
  9. data/lib/xpost/configuration.rb +15 -0
  10. data/lib/xpost/item.rb +44 -0
  11. data/lib/xpost/order.rb +137 -0
  12. data/lib/xpost/orders.rb +53 -12
  13. data/lib/xpost/statuses.rb +29 -0
  14. data/lib/xpost/version.rb +1 -1
  15. data/sample/sample_essential_order_details.json +64 -0
  16. data/sample/sample_xpost_order-confirmed.json +317 -0
  17. data/sample/sample_xpost_order-for-pickup.json +379 -0
  18. data/sample/sample_xpost_order-pending.json +306 -0
  19. data/sample/webhook_sample.json +105 -0
  20. data/spec/factories/addresses.rb +46 -28
  21. data/spec/factories/items.rb +10 -10
  22. data/spec/factories/orders.rb +39 -16
  23. data/spec/{address_spec.rb → order/address/address_spec.rb} +0 -0
  24. data/spec/order/cancel_spec.rb +37 -0
  25. data/spec/order/confirm_spec.rb +38 -0
  26. data/spec/order/create_spec.rb +97 -0
  27. data/spec/order/for_pickup_spec.rb +42 -0
  28. data/spec/order/get_shipping_label_spec.rb +60 -0
  29. data/spec/{item_spec.rb → order/items/item_spec.rb} +5 -5
  30. data/spec/order/order_spec.rb +97 -0
  31. data/spec/orders/{orders_find_spec.rb → find_spec.rb} +3 -2
  32. data/spec/orders/{orders_track_spec.rb → track_spec.rb} +2 -2
  33. data/spec/spec_helper.rb +1 -0
  34. data/spec/xpost_spec.rb +27 -0
  35. data/xpost.gemspec +5 -2
  36. metadata +67 -15
  37. data/lib/xpost/models.rb +0 -5
  38. data/lib/xpost/models/address.rb +0 -38
  39. data/lib/xpost/models/item.rb +0 -31
  40. data/lib/xpost/models/order.rb +0 -54
  41. data/spec/line_item_spec.rb +0 -16
  42. data/spec/orders/order_create_spec.rb +0 -46
  43. data/spec/orders/order_for_pickup_spec.rb +0 -17
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  RSpec.describe "Orders.find" do
4
4
  before do
5
5
  Xpost.configure do |config|
6
- config.api_key = 'api_key'
7
- config.secret_key = 'secret_key'
6
+ config.api_key = ENV['XPOST_STAGING_API_KEY']
7
+ config.secret_key = ENV['XPOST_STAGING_SECRET_KEY']
8
8
  config.staging_url = "https://api.staging.lbcx.ph/v1"
9
9
  config.production_url = "https://api.staging.lbcx.ph/v1"
10
10
  end
@@ -16,6 +16,7 @@ RSpec.describe "Orders.find" do
16
16
  order = Xpost::Orders.find(@auth_token, tracking_number)
17
17
 
18
18
  expect(order[:id]).to eq 761174
19
+ expect(order[:tracking_number]).to eq "0076-1174-PSAT"
19
20
  end
20
21
 
21
22
  it 'fails on an invalid order' do
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  RSpec.describe "Orders.track" do
4
4
  before do
5
5
  Xpost.configure do |config|
6
- config.api_key = 'api_key'
7
- config.secret_key = 'secret_key'
6
+ config.api_key = ENV['XPOST_STAGING_API_KEY']
7
+ config.secret_key = ENV['XPOST_STAGING_SECRET_KEY']
8
8
  config.staging_url = "https://api.staging.lbcx.ph/v1"
9
9
  config.production_url = "https://api.staging.lbcx.ph/v1"
10
10
  end
@@ -1,5 +1,6 @@
1
1
  require 'bundler/setup'
2
2
  require 'factory_bot'
3
+ require 'dotenv/load'
3
4
  require 'xpost'
4
5
 
5
6
  require 'helpers'
@@ -33,5 +33,32 @@ RSpec.describe Xpost do
33
33
  end
34
34
  end
35
35
  end
36
+
37
+ describe 'Statuses' do
38
+ before do
39
+ Xpost.configure do |config|
40
+ config.api_key = ENV['XPOST_STAGING_API_KEY']
41
+ config.secret_key = ENV['XPOST_STAGING_SECRET_KEY']
42
+ config.staging_url = "https://api.staging.lbcx.ph/v1"
43
+ config.production_url = "https://api.staging.lbcx.ph/v1"
44
+ end
45
+ @auth_token = Xpost::Authentication.authenticate(Xpost.configuration.api_key, Xpost.configuration.secret_key)
46
+ end
47
+
48
+ it 'returns statuses' do
49
+ statuses = Xpost::Statuses.all(@auth_token)
50
+
51
+ expect(statuses.count).to_not eq 0
52
+ expect(statuses.first[:name]).to eq "pending"
53
+ expect(statuses.first[:label]).to eq "Pending"
54
+ end
55
+
56
+ it 'fails to retrieve statuses with an invalid auth_token' do
57
+ statuses = Xpost::Statuses.all("random_invalid_auth_token")
58
+
59
+ expect(statuses[:status]).to eq 401
60
+ expect(statuses[:message]).to eq "Unauthorized"
61
+ end
62
+ end
36
63
  end
37
64
 
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = 'david@xpanse.ph'
10
10
 
11
11
  s.summary = "xpost Ruby API"
12
- s.date = '2018-04-27'
12
+ s.date = '2018-08-09'
13
13
  s.description = "A quick wrapped of the xpost API written by xpanse."
14
14
  s.homepage = 'http://rubygems.org/gems/xpost'
15
15
  s.license = 'MIT'
@@ -17,12 +17,15 @@ Gem::Specification.new do |s|
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency 'activemodel', '~> 5.2'
20
+ s.add_dependency 'activemodel', '~> 5.1'
21
21
  s.add_dependency 'typhoeus', '~> 1.3'
22
22
  s.add_dependency 'factory_bot', '~> 4.8'
23
+ s.add_dependency 'fast_jsonapi', '~> 1.3'
23
24
  # s.add_dependency 'vcr', '~> 4.0'
24
25
 
25
26
  s.add_development_dependency 'bundler', "~> 1.16"
27
+ s.add_development_dependency 'faker', "~> 1.9"
26
28
  s.add_development_dependency 'rake', "~> 12.3"
27
29
  s.add_development_dependency 'rspec', '~> 3.2'
30
+ s.add_development_dependency 'dotenv', '~> 2.5'
28
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xpost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Marquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-27 00:00:00.000000000 Z
11
+ date: 2018-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '5.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.2'
26
+ version: '5.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: typhoeus
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fast_jsonapi
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '1.16'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faker
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.9'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rake
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +122,20 @@ dependencies:
94
122
  - - "~>"
95
123
  - !ruby/object:Gem::Version
96
124
  version: '3.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: dotenv
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.5'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.5'
97
139
  description: A quick wrapped of the xpost API written by xpanse.
98
140
  email: david@xpanse.ph
99
141
  executables: []
@@ -107,26 +149,36 @@ files:
107
149
  - LICENSE
108
150
  - README.md
109
151
  - TODO.md
152
+ - lib/.DS_Store
110
153
  - lib/xpost.rb
154
+ - lib/xpost/.DS_Store
155
+ - lib/xpost/address.rb
111
156
  - lib/xpost/authentication.rb
112
157
  - lib/xpost/configuration.rb
113
- - lib/xpost/models.rb
114
- - lib/xpost/models/address.rb
115
- - lib/xpost/models/item.rb
116
- - lib/xpost/models/order.rb
158
+ - lib/xpost/item.rb
159
+ - lib/xpost/order.rb
117
160
  - lib/xpost/orders.rb
161
+ - lib/xpost/statuses.rb
118
162
  - lib/xpost/version.rb
119
- - spec/address_spec.rb
163
+ - sample/sample_essential_order_details.json
164
+ - sample/sample_xpost_order-confirmed.json
165
+ - sample/sample_xpost_order-for-pickup.json
166
+ - sample/sample_xpost_order-pending.json
167
+ - sample/webhook_sample.json
120
168
  - spec/factories/addresses.rb
121
169
  - spec/factories/items.rb
122
170
  - spec/factories/orders.rb
123
171
  - spec/helpers.rb
124
- - spec/item_spec.rb
125
- - spec/line_item_spec.rb
126
- - spec/orders/order_create_spec.rb
127
- - spec/orders/order_for_pickup_spec.rb
128
- - spec/orders/orders_find_spec.rb
129
- - spec/orders/orders_track_spec.rb
172
+ - spec/order/address/address_spec.rb
173
+ - spec/order/cancel_spec.rb
174
+ - spec/order/confirm_spec.rb
175
+ - spec/order/create_spec.rb
176
+ - spec/order/for_pickup_spec.rb
177
+ - spec/order/get_shipping_label_spec.rb
178
+ - spec/order/items/item_spec.rb
179
+ - spec/order/order_spec.rb
180
+ - spec/orders/find_spec.rb
181
+ - spec/orders/track_spec.rb
130
182
  - spec/spec_helper.rb
131
183
  - spec/xpost_spec.rb
132
184
  - xpost.gemspec
@@ -1,5 +0,0 @@
1
- module Xpost
2
- module Models
3
-
4
- end
5
- end
@@ -1,38 +0,0 @@
1
- require 'active_model'
2
- require 'set'
3
-
4
- module Xpost
5
- module Models
6
- class Address
7
- include ActiveModel::Model
8
-
9
- REQUIRED_ADDRESS_PARAMETERS = Set[:name, :shipment, :line_1, :city, :state, :postal_code, :country]
10
- OPTIONAL_ADDRESS_PARAMETERS = Set[:company, :title, :email, :phone_number, :mobile_number, :fax_number,
11
- :district, :line_2, :remarks]
12
-
13
- attr_accessor :name, :shipment, :line_1, :city, :state, :postal_code, :country
14
- attr_accessor :company, :title, :email, :phone_number, :mobile_number, :fax_number, :district, :line_2, :remarks
15
-
16
- validates_presence_of :name, :shipment, :line_1, :city, :state, :postal_code, :country
17
-
18
- def initialize(options = {})
19
- @shipment = options[:shipment]
20
- @name = options[:name]
21
- @email = options[:email]
22
- @phone_number = options[:phone_number]
23
- @mobile_number = options[:mobile_number]
24
- @fax_number = options[:fax_number]
25
- @company = options[:company]
26
- @title = options[:title]
27
- @line_1 = options[:line_1]
28
- @line_2 = options[:line_2]
29
- @city = options[:city]
30
- @district = options[:district]
31
- @state = options[:state]
32
- @postal_code = options[:postal_code]
33
- @country = options[:country]
34
- @remarks = options[:remarks]
35
- end
36
- end
37
- end
38
- end
@@ -1,31 +0,0 @@
1
- require 'active_model'
2
- require 'set'
3
-
4
- module Xpost
5
- module Models
6
- class Item
7
- include ActiveModel::Model
8
-
9
- ITEM_TYPES = Set[:product, :shipping, :tax, :fee, :insurance, :discount]
10
-
11
- attr_accessor :type, :description, :amount, :quantity, :metadata
12
-
13
- validates_presence_of :type, :description, :amount
14
- validate :check_item_type
15
-
16
- def initialize(options = {})
17
- @type = options[:type]
18
- @description = options[:description]
19
- @amount = options[:amount]
20
- @quantity = options[:quantity]
21
- @metadata = options[:metadata]
22
- end
23
-
24
- def check_item_type
25
- if self.type.present? && !ITEM_TYPES.include?(self.type.to_sym)
26
- errors.add(:type, "wrong item type")
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,54 +0,0 @@
1
- require 'active_model'
2
- require 'set'
3
-
4
- module Xpost
5
- module Models
6
- class Order
7
- include ActiveModel::Model
8
-
9
- CONFIRMABLE_PARAMETERS = Set[:status, :email, :buyer_name, :contact_number, :delivery_address, :items,
10
- :shipment, :total, :currency, :payment_method, :payment_provider]
11
- FOR_PICKUP_PARAMETERS = Set[:pickup_address, :pickup_at]
12
-
13
- attr_accessor :email, :buyer_name, :contact_number
14
- attr_accessor :total, :currency, :payment_method, :payment_provider
15
- attr_accessor :delivery_address, :pickup_address
16
- attr_accessor :status, :items, :shipment
17
-
18
- validates_presence_of :email, :buyer_name, :contact_number
19
- validates_presence_of :delivery_address
20
-
21
- def initialize(options = {})
22
- @status = options[:status]
23
- @email = options[:email]
24
- @buyer_name = options[:buyer_name]
25
- @contact_number = options[:contact_number]
26
- @delivery_address = options[:delivery_address]
27
- @items = options[:items]
28
- @shipment = options[:shipment]
29
- @total = options[:total]
30
- @currency = options[:currency]
31
- @payment_method = options[:payment_method]
32
- @payment_provider = options[:payment_provider]
33
- @pickup_address = options[:pickup_address]
34
- @pickup_at = options[:pickup_at]
35
- end
36
-
37
- def confirmable?
38
- self.valid? && self.delivery_address.present?
39
- end
40
-
41
- # https://docs.quadx.xyz/#5f38afd0-66bb-468f-ab4e-993d4745a257
42
- # Sets the order status to canceled. An order can be canceled provided they have not passed the cutoff date and time as specified in the contract.
43
- def cancellable?
44
- true
45
- end
46
-
47
- # https://docs.quadx.xyz/#c831dc25-2de4-36c5-c321-8e9db0fc2105
48
- # The following fields can be updated provided they have not passed the cutoff date and time as specified in the contract.
49
- def updatable?
50
- true
51
- end
52
- end
53
- end
54
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'LineItem' do
4
-
5
- describe 'with require parameters' do
6
- # it 'is valid' do
7
- # line_item = build(:line_item)
8
- # expect(line_item).to be_valid
9
- # end
10
-
11
- # it 'is invalid with missing parameters' do
12
- # line_item = build(:line_item, type: nil)
13
- # expect(line_item).not_to be_valid
14
- # end
15
- end
16
- end
@@ -1,46 +0,0 @@
1
- require 'set'
2
- require 'spec_helper'
3
-
4
- RSpec.describe "Orders.create" do
5
- before(:each) do
6
- @order = build(:order)
7
- end
8
-
9
- it 'requires a delivery address' do
10
- order_without_delivery_address = build(:order, delivery_address: nil)
11
- order_with_delivery_address = build(:order)
12
- expect(order_without_delivery_address).not_to be_valid
13
- expect(order_with_delivery_address).to be_valid
14
- end
15
-
16
- it 'requires a payment method' do
17
- expect(@order.payment_method).to be_present
18
- expect(@order.payment_provider).to be_present
19
- end
20
-
21
- it 'requires at least one product in line items' do
22
- expect(@order.items.count).to eq 1
23
- expect(@order.items.first.description).to eq "red shirt"
24
- end
25
-
26
- # TODO: Skipping calls for now to prevent multiple
27
- # orders from being added to the staging site.
28
-
29
-
30
- # it 'creates an order' do
31
- # auth_token = Xpost::Authentication.local_auth
32
- # @res = Xpost::Orders.create(auth_token, @order)
33
- # expect(@res[:tracking_number]).to eq 200
34
- # end
35
-
36
- # describe 'returning a valid order object' do
37
- # before(:each) do
38
- # auth_token = Xpost::Authentication.local_auth
39
- # @res = Xpost::Orders.create(auth_token, @order)
40
- # end
41
-
42
- # it 'has a tracking number'
43
- # it 'has a status of confirming'
44
- # end
45
-
46
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe "@order.for_pickup" do
4
- before do
5
- Xpost.configure do |config|
6
- config.api_key = 'api_key'
7
- config.secret_key = 'secret_key'
8
- config.staging_url = "https://api.staging.lbcx.ph/v1"
9
- config.production_url = "https://api.staging.lbcx.ph/v1"
10
- end
11
- @auth_token = Xpost::Authentication.authenticate(Xpost.configuration.api_key, Xpost.configuration.secret_key)
12
- end
13
-
14
- it 'already has a delivery address'
15
- it 'requires a pickup address'
16
-
17
- end