xpost 0.1.22 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/TODO.md +28 -1
- data/lib/.DS_Store +0 -0
- data/lib/xpost.rb +8 -6
- data/lib/xpost/.DS_Store +0 -0
- data/lib/xpost/address.rb +77 -0
- data/lib/xpost/authentication.rb +5 -0
- data/lib/xpost/configuration.rb +15 -0
- data/lib/xpost/item.rb +44 -0
- data/lib/xpost/order.rb +137 -0
- data/lib/xpost/orders.rb +53 -12
- data/lib/xpost/statuses.rb +29 -0
- data/lib/xpost/version.rb +1 -1
- data/sample/sample_essential_order_details.json +64 -0
- data/sample/sample_xpost_order-confirmed.json +317 -0
- data/sample/sample_xpost_order-for-pickup.json +379 -0
- data/sample/sample_xpost_order-pending.json +306 -0
- data/sample/webhook_sample.json +105 -0
- data/spec/factories/addresses.rb +46 -28
- data/spec/factories/items.rb +10 -10
- data/spec/factories/orders.rb +39 -16
- data/spec/{address_spec.rb → order/address/address_spec.rb} +0 -0
- data/spec/order/cancel_spec.rb +37 -0
- data/spec/order/confirm_spec.rb +38 -0
- data/spec/order/create_spec.rb +97 -0
- data/spec/order/for_pickup_spec.rb +42 -0
- data/spec/order/get_shipping_label_spec.rb +60 -0
- data/spec/{item_spec.rb → order/items/item_spec.rb} +5 -5
- data/spec/order/order_spec.rb +97 -0
- data/spec/orders/{orders_find_spec.rb → find_spec.rb} +3 -2
- data/spec/orders/{orders_track_spec.rb → track_spec.rb} +2 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/xpost_spec.rb +27 -0
- data/xpost.gemspec +3 -0
- metadata +64 -12
- data/lib/xpost/models.rb +0 -5
- data/lib/xpost/models/address.rb +0 -38
- data/lib/xpost/models/item.rb +0 -31
- data/lib/xpost/models/order.rb +0 -54
- data/spec/line_item_spec.rb +0 -16
- data/spec/orders/order_create_spec.rb +0 -46
- 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 = '
|
7
|
-
config.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 = '
|
7
|
-
config.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
|
data/spec/spec_helper.rb
CHANGED
data/spec/xpost_spec.rb
CHANGED
@@ -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
|
|
data/xpost.gemspec
CHANGED
@@ -20,9 +20,12 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_dependency 'activemodel', '~> 5.2'
|
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xpost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Marquez
|
@@ -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/
|
114
|
-
- lib/xpost/
|
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
|
-
-
|
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/
|
125
|
-
- spec/
|
126
|
-
- spec/
|
127
|
-
- spec/
|
128
|
-
- spec/
|
129
|
-
- spec/
|
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
|
data/lib/xpost/models.rb
DELETED
data/lib/xpost/models/address.rb
DELETED
@@ -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
|
data/lib/xpost/models/item.rb
DELETED
@@ -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
|
data/lib/xpost/models/order.rb
DELETED
@@ -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
|
data/spec/line_item_spec.rb
DELETED
@@ -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
|