ship_station 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 +4 -4
- data/lib/ship_station/api/model.rb +24 -9
- data/lib/ship_station/api/order.rb +5 -0
- data/lib/ship_station/api.rb +14 -9
- data/lib/ship_station/base.rb +17 -8
- data/lib/ship_station/middleware.rb +3 -4
- data/lib/ship_station/version.rb +1 -1
- data/lib/ship_station.rb +2 -2
- data/spec/ship_station/base_spec.rb +0 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9e8ae106f4ee30f1a8fdad291e02a6093716a6b
|
4
|
+
data.tar.gz: 89cbb419ebaae46c18c68f04f886808029ea8252
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb145eacbfa6be322a3703210b442550fd4e3715c67d5078b1a9a0256079b32a26b02bc3b22ed765de8dfaf2d4732ad4682f53029530b7076549efcd0ba149cb
|
7
|
+
data.tar.gz: 0d5eb871ecb14abd8d4f44beaed22551525e83c4e3c0b93743b108b598c0f46cf18ea8150d66110a24fa1eb3bc38bbdab968b729b74b77f3c10269fe9f42edcb
|
@@ -1,20 +1,35 @@
|
|
1
1
|
module ShipStation
|
2
2
|
class Model
|
3
|
-
Her::API.setup
|
4
3
|
include Her::Model
|
5
4
|
use_api V1::API
|
6
5
|
parse_root_in_json true, format: :active_model_serializers
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
class << self
|
8
|
+
%w(where find create new save_existing destroy_existing).each do |name|
|
9
|
+
define_method "#{name}" do |i|
|
10
|
+
raise(ConfigurationError, "Shipstation username not configured") if ShipStation.username.nil?
|
11
|
+
raise(ConfigurationError, "Shipstation password not configured") if ShipStation.password.nil?
|
12
|
+
super(i)
|
13
|
+
end
|
14
|
+
end
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
def all
|
17
|
+
raise(ConfigurationError, "Shipstation username not configured") if ShipStation.username.nil?
|
18
|
+
raise(ConfigurationError, "Shipstation password not configured") if ShipStation.password.nil?
|
19
|
+
super
|
20
|
+
end
|
15
21
|
|
16
|
-
|
17
|
-
|
22
|
+
def associated
|
23
|
+
@associated ||= {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def shipstation_has_many(name, opts={})
|
27
|
+
associated[name] = opts.merge(:relationship => :has_many)
|
28
|
+
end
|
29
|
+
|
30
|
+
def shipstation_belongs_to(name, opts={})
|
31
|
+
associated[name] = opts.merge(:relationship => :belongs_to)
|
32
|
+
end
|
18
33
|
end
|
19
34
|
|
20
35
|
def method_missing(name, *args, &block)
|
data/lib/ship_station/api.rb
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
module ShipStation
|
2
2
|
module V1
|
3
3
|
API = Her::API.new
|
4
|
-
API.setup url: "https://ssapi.shipstation.com" do |c|
|
5
|
-
#Authentication
|
6
|
-
c.use Faraday::Request::BasicAuthentication, ShipStation.username, ShipStation.password
|
7
4
|
|
8
|
-
|
9
|
-
|
5
|
+
def self.setup
|
6
|
+
puts "Initializing API Setup"
|
7
|
+
API.setup url: "https://ssapi.shipstation.com" do |c|
|
8
|
+
#Authentication
|
9
|
+
c.use Faraday::Request::BasicAuthentication, ShipStation.username, ShipStation.password
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
# Request
|
12
|
+
c.use ShipStation::Middleware::JSONRequest
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
# Response
|
15
|
+
c.use ShipStation::Middleware::ResponseParser
|
16
|
+
|
17
|
+
# Adapter
|
18
|
+
c.use Faraday::Adapter::NetHttp
|
19
|
+
end
|
20
|
+
puts "API Setup Complete."
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
data/lib/ship_station/base.rb
CHANGED
@@ -7,24 +7,33 @@ module ShipStation
|
|
7
7
|
class << self
|
8
8
|
extend ActiveSupport::Autoload
|
9
9
|
|
10
|
-
attr_writer :username
|
11
|
-
attr_writer :password
|
12
|
-
|
13
10
|
attr_accessor :limit
|
14
11
|
attr_accessor :remaining
|
15
12
|
attr_accessor :reset_time
|
16
13
|
|
17
14
|
def username
|
18
|
-
@username ||= ENV["SHIPSTATION_API_KEY"]
|
19
|
-
|
15
|
+
@username ||= ENV["SHIPSTATION_API_KEY"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def username=(arg)
|
19
|
+
@username = arg
|
20
|
+
ShipStation::V1.setup
|
21
|
+
@password
|
20
22
|
end
|
21
23
|
|
22
24
|
def password
|
23
|
-
@password ||= ENV["SHIPSTATION_API_SECRET"]
|
24
|
-
raise(ConfigurationError, "Shipstation password not configured")
|
25
|
+
@password ||= ENV["SHIPSTATION_API_SECRET"]
|
25
26
|
end
|
26
27
|
|
28
|
+
def password=(arg)
|
29
|
+
@password = arg
|
30
|
+
ShipStation::V1.setup
|
31
|
+
@password
|
32
|
+
end
|
33
|
+
|
34
|
+
|
27
35
|
end
|
28
36
|
end
|
29
37
|
|
30
|
-
SS = ShipStation
|
38
|
+
SS = ShipStation
|
39
|
+
SS::V1.setup if ShipStation.username && ShipStation.password
|
@@ -8,6 +8,8 @@ module ShipStation
|
|
8
8
|
|
9
9
|
errors = json.delete(:errors) || {}
|
10
10
|
pagination = json.slice(:page, :pages, :total)
|
11
|
+
|
12
|
+
#change to new hash style
|
11
13
|
{
|
12
14
|
:data => json.except(:page, :pages, :total),
|
13
15
|
:errors => errors,
|
@@ -33,11 +35,8 @@ module ShipStation
|
|
33
35
|
|
34
36
|
# @private
|
35
37
|
def call(env)
|
36
|
-
# puts "########Request Url############"
|
37
|
-
# puts env.url
|
38
|
-
# puts "###############################"
|
39
38
|
unless env.method == :get
|
40
|
-
env[:body] = encode env[:body] unless env[:body].respond_to?(:
|
39
|
+
env[:body] = encode env[:body] unless env[:body].respond_to?(:to_s)
|
41
40
|
end
|
42
41
|
@app.call(env)
|
43
42
|
end
|
data/lib/ship_station/version.rb
CHANGED
data/lib/ship_station.rb
CHANGED
@@ -1,16 +1,4 @@
|
|
1
1
|
RSpec.describe ShipStation do
|
2
|
-
it "raises configurations error if missing API key" do
|
3
|
-
ENV["SHIPSTATION_API_KEY"] = nil
|
4
|
-
ShipStation.username = nil
|
5
|
-
expect{ ShipStation.username }.to raise_error(ShipStation::ConfigurationError)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "raises configurations error if missing API secret" do
|
9
|
-
ENV["SHIPSTATION_API_SECRET"] = nil
|
10
|
-
ShipStation.password = nil
|
11
|
-
expect{ ShipStation.password }.to raise_error(ShipStation::ConfigurationError)
|
12
|
-
end
|
13
|
-
|
14
2
|
it "stores rate limiting information after each request" do
|
15
3
|
stub_api_for(ShipStation::Order) do |stub|
|
16
4
|
stub.get("/orders") do |env|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ship_station
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Jacobs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: her
|