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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d541da1b8d5a90890bcaa731a0234eea3c76b15d
4
- data.tar.gz: cea268522b3bd920af0eba90432829e1e8827cf8
3
+ metadata.gz: e9e8ae106f4ee30f1a8fdad291e02a6093716a6b
4
+ data.tar.gz: 89cbb419ebaae46c18c68f04f886808029ea8252
5
5
  SHA512:
6
- metadata.gz: ca7e489d5a5244c1ef29c7c592f7f9f461d2853ab235ba0927a12befd0910ffe11ea03e132e88b2fbf9030bdf43f3c6fb690a4e97934daea773595e54cd140a7
7
- data.tar.gz: eb73d08ff8fdb0e2623c41bf5a258cc6198219083ce43715aeb252151b5e4118904e0e7943c395792b0df5719e13b12b9489f3c824896e4a72f9bf002c6f2439
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
- def self.associated
9
- @associated ||= {}
10
- end
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
- def self.shipstation_has_many(name, opts={})
13
- self.associated[name] = opts.merge(:relationship => :has_many)
14
- end
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
- def self.shipstation_belongs_to(name, opts={})
17
- self.associated[name] = opts.merge(:relationship => :belongs_to)
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)
@@ -2,5 +2,10 @@ module ShipStation
2
2
  class Order < Model
3
3
  shipstation_has_many :shipments, foreign_key: :orderNumber
4
4
  shipstation_belongs_to :customer, primary_key: :customerId
5
+
6
+ def all(args)
7
+ use_api V1::API
8
+ super(args)
9
+ end
5
10
  end
6
11
  end
@@ -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
- # Request
9
- c.use ShipStation::Middleware::JSONRequest
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
- # Response
12
- c.use ShipStation::Middleware::ResponseParser
11
+ # Request
12
+ c.use ShipStation::Middleware::JSONRequest
13
13
 
14
- # Adapter
15
- c.use Faraday::Adapter::NetHttp
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
@@ -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"] or
19
- raise(ConfigurationError, "Shipstation username not configured")
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"] or
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?(:to_str)
39
+ env[:body] = encode env[:body] unless env[:body].respond_to?(:to_s)
41
40
  end
42
41
  @app.call(env)
43
42
  end
@@ -1,3 +1,3 @@
1
1
  module ShipStation
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/ship_station.rb CHANGED
@@ -6,9 +6,9 @@ require 'logger'
6
6
  require 'her'
7
7
 
8
8
  # App
9
- require 'ship_station/base'
10
- require 'ship_station/middleware'
11
9
  require 'ship_station/api'
10
+ require 'ship_station/middleware'
11
+ require 'ship_station/base'
12
12
 
13
13
  # Models
14
14
  require 'ship_station/api/model'
@@ -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.3
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-10-29 00:00:00.000000000 Z
11
+ date: 2018-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: her