Module: Shiphawk::Api::QueryHelpers

Included in:
Client
Defined in:
lib/shiphawk/api/query_helpers.rb

Instance Method Summary collapse

Instance Method Details

#catalog_sale_pathObject



42
43
44
# File 'lib/shiphawk/api/query_helpers.rb', line 42

def catalog_sale_path
  notifications_path "catalog_sale"
end

#categories_path(sub_path = nil) ⇒ Object



10
11
12
# File 'lib/shiphawk/api/query_helpers.rb', line 10

def categories_path sub_path=nil
  "categories/#{sub_path}"
end

#collection_request(path, count = 100) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/shiphawk/api/query_helpers.rb', line 50

def collection_request path, count=100
  page = 1
  entities = []
  loop do
    response = get_request path, {page: page, per_page: count, api_token: self.api_token}
    entities << response.body
    entities = entities.flatten
    break if entities.size >= response.headers['X-Total'].to_i
    page += 1
  end
  entities
end

#entity_request_with_id(path, id) ⇒ Object



63
64
65
# File 'lib/shiphawk/api/query_helpers.rb', line 63

def entity_request_with_id path, id
  get_request "#{path}#{id}", {}
end

#entity_request_with_options(path, options) ⇒ Object



67
68
69
# File 'lib/shiphawk/api/query_helpers.rb', line 67

def entity_request_with_options path, options
  get_request path, options
end

#items_path(sub_path = nil) ⇒ Object



6
7
8
# File 'lib/shiphawk/api/query_helpers.rb', line 6

def items_path sub_path=nil
  "items/#{sub_path}"
end

#notes_path(id) ⇒ Object



22
23
24
# File 'lib/shiphawk/api/query_helpers.rb', line 22

def notes_path id
  shipments_path "#{id}/notes"
end

#notifications_path(sub_path = nil) ⇒ Object



38
39
40
# File 'lib/shiphawk/api/query_helpers.rb', line 38

def notifications_path sub_path=nil
  "notifications/#{sub_path}"
end

#products_path(sub_path = nil) ⇒ Object



14
15
16
# File 'lib/shiphawk/api/query_helpers.rb', line 14

def products_path sub_path=nil
  "products/#{sub_path}"
end

#rates_path(sub_path = nil) ⇒ Object



18
19
20
# File 'lib/shiphawk/api/query_helpers.rb', line 18

def rates_path sub_path=nil
  "rates/#{sub_path}"
end

#shipments_path(sub_path = nil) ⇒ Object



30
31
32
# File 'lib/shiphawk/api/query_helpers.rb', line 30

def shipments_path sub_path=nil
  "shipments/#{sub_path}"
end

#status_pathObject



34
35
36
# File 'lib/shiphawk/api/query_helpers.rb', line 34

def status_path
  shipments_path "status"
end

#tracking_path(id) ⇒ Object



26
27
28
# File 'lib/shiphawk/api/query_helpers.rb', line 26

def tracking_path id
  shipments_path "#{id}/tracking"
end

#zip_codes_path(sub_path = nil) ⇒ Object



46
47
48
# File 'lib/shiphawk/api/query_helpers.rb', line 46

def zip_codes_path sub_path=nil
  "zip_codes/#{sub_path}"
end