Module: Shipstation

Defined in:
lib/shipstation.rb,
lib/shipstation/tag.rb,
lib/shipstation/order.rb,
lib/shipstation/store.rb,
lib/shipstation/carrier.rb,
lib/shipstation/product.rb,
lib/shipstation/version.rb,
lib/shipstation/customer.rb,
lib/shipstation/shipment.rb,
lib/shipstation/warehouse.rb,
lib/shipstation/api_resource.rb,
lib/shipstation/api_operations/list.rb,
lib/shipstation/api_operations/create.rb,
lib/shipstation/api_operations/delete.rb,
lib/shipstation/api_operations/update.rb,
lib/shipstation/api_operations/retrieve.rb

Defined Under Namespace

Modules: APIOperations Classes: ApiResource, AuthenticationError, Carrier, ConfigurationError, Customer, Order, Product, Shipment, ShipstationError, Store, Tag, Warehouse

Constant Summary collapse

API_BASE =
"https://ssapi.shipstation.com/"
VERSION =
"0.14.5"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.passwordObject



36
37
38
39
40
# File 'lib/shipstation.rb', line 36

def password
    defined? @password and @password or raise(
        ConfigurationError, "Shipstation password not configured"
    )
end

.usernameObject



29
30
31
32
33
# File 'lib/shipstation.rb', line 29

def username
    defined? @username and @username or raise(
        ConfigurationError, "Shipstation username not configured"
    )
end

Class Method Details

.datetime_format(datetime) ⇒ Object



75
76
77
# File 'lib/shipstation.rb', line 75

def datetime_format datetime
    datetime.strftime("%Y-%m-%d %T")
end

.request(method, resource, params = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/shipstation.rb', line 43

def request method, resource, params={}
    ss_username = params[:username] || Shipstation.username
    ss_password = params[:password] || Shipstation.password

    params.except!(:username, :password)

    defined? method or raise(
        ArgumentError, "Request method has not been specified"
    )
    defined? resource or raise(
        ArgumentError, "Request resource has not been specified"
    )
    if method == :get 
        headers = { :accept => :json, content_type: :json }.merge({params: params})
        payload = nil
    else
        headers = { :accept => :json, content_type: :json }
        payload = params
    end
    RestClient::Request.new({
        method: method,
        url: API_BASE + resource,
        user: ss_username,
        password: ss_password,
        payload: payload ? payload.to_json : nil,
        headers: headers
    }).execute do |response, request, result|
        str_response = response.to_str        
        str_response.blank? ? '' : JSON.parse(str_response)
    end
end