Class: ShipitAPI::Package
- Inherits:
-
Object
- Object
- ShipitAPI::Package
- Defined in:
- lib/shipit_api/package.rb
Class Method Summary collapse
Instance Method Summary collapse
- #address_attrs ⇒ Object
- #all ⇒ Object
- #attrs ⇒ Object
- #build! ⇒ Object
- #destroy ⇒ Object
- #find(opts = opts) ⇒ Object
- #fulfillment_attrs ⇒ Object
-
#initialize(opts = {}) ⇒ Package
constructor
A new instance of Package.
- #latest ⇒ Object
- #purchase_attrs ⇒ Object
- #save ⇒ Object
- #sku_attrs ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Package
Returns a new instance of Package.
19 20 21 22 23 |
# File 'lib/shipit_api/package.rb', line 19 def initialize(opts = {}) @opts = opts @api_call = ShipitAPI::Session.connection(self.class.name) build! if !@opts.kind_of?(Array) end |
Class Method Details
.all(opts = {}) ⇒ Object
3 4 5 |
# File 'lib/shipit_api/package.rb', line 3 def self.all(opts = {}) new(opts).all end |
.create(opts = {}) ⇒ Object
7 8 9 |
# File 'lib/shipit_api/package.rb', line 7 def self.create(opts = {}) new(opts).save end |
.find(opts = {}) ⇒ Object
11 12 13 |
# File 'lib/shipit_api/package.rb', line 11 def self.find(opts = {}) new().find(opts) end |
.latest ⇒ Object
15 16 17 |
# File 'lib/shipit_api/package.rb', line 15 def self.latest new().latest end |
Instance Method Details
#address_attrs ⇒ Object
31 32 33 |
# File 'lib/shipit_api/package.rb', line 31 def address_attrs { commune_id: nil, street: "", number: "", complement: "" } end |
#all ⇒ Object
54 55 56 57 58 |
# File 'lib/shipit_api/package.rb', line 54 def all @opts = @opts.empty? ? { year: Time.now.year, month: Time.now.month } : @opts response = @api_call.get('', @opts) JSON.parse(response.body, symbolize_names: true) end |
#attrs ⇒ Object
25 26 27 28 29 |
# File 'lib/shipit_api/package.rb', line 25 def attrs { reference: "", full_name: "", email: "", items_count: 1, cellphone: "", is_payable: false, packing: "Sin Empaque", shipping_type: "Normal", destiny: "Domicilio", courier_for_client: nil, address_attributes: address_attrs, with_purchase_insurance: false, purchase: purchase_attrs, inventory_activity: fulfillment_attrs } end |
#build! ⇒ Object
47 48 49 50 51 52 |
# File 'lib/shipit_api/package.rb', line 47 def build! @opts.each do |k,v| singleton_class.send(:attr_accessor, k) instance_variable_set("@#{k}", v) end end |
#destroy ⇒ Object
72 73 |
# File 'lib/shipit_api/package.rb', line 72 def destroy end |
#find(opts = opts) ⇒ Object
60 61 62 63 64 |
# File 'lib/shipit_api/package.rb', line 60 def find(opts = opts) opts = opts.empty? ? StandardError : opts response = @api_call.get("#{opts[:id]}") JSON.parse(response.body, symbolize_names: true) end |
#fulfillment_attrs ⇒ Object
39 40 41 |
# File 'lib/shipit_api/package.rb', line 39 def fulfillment_attrs { inventory_activity_orders_attributes: [] } end |
#latest ⇒ Object
75 76 77 78 79 |
# File 'lib/shipit_api/package.rb', line 75 def latest @opts = @opts.empty? ? { year: Time.now.year, month: Time.now.month } : @opts response = @api_call.get('', @opts) JSON.parse(response.body, symbolize_names: true).last end |
#purchase_attrs ⇒ Object
35 36 37 |
# File 'lib/shipit_api/package.rb', line 35 def purchase_attrs { detail: "Ropa", ticket_number: 11111111, amount: 0, extra_insurance: false } end |
#save ⇒ Object
66 67 68 69 70 |
# File 'lib/shipit_api/package.rb', line 66 def save @opts = @opts.empty? ? StandardError : @opts response = @api_call.post('mass_create', { packages: @opts }.to_json) JSON.parse(response.body, symbolize_names: true) end |
#sku_attrs ⇒ Object
43 44 45 |
# File 'lib/shipit_api/package.rb', line 43 def sku_attrs { sku_id: nil, amount: 1 } end |