Sha256: 311579812e88c05db900bcc22b8d9e1ef9c1bd6cd1dbbd21d3bda5873eacc629

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

module ShiprocketAPI
  class PickupLocation < Base
    self.prefix += "/settings/company/addpickup"
    self.element_name = ""

    class Collection < ActiveResource::Collection
      def initialize(parsed = {})
        @elements = parsed["shipping_address"]
      end
    end
    self.collection_parser = Collection

    DEFAULT_ATTRS = {
      pickup_location: "",
      name: "",
      email: "",
      phone: "",
      address: "",
      address_2: "",
      city: "",
      state: "",
      country: "",
      pin_code: ""
    }

    class << self

      def set_prefix_to_list_all_locations
        set_prefix("#{Base.prefix}/settings/company/pickup") do
          yield
        end
      end

      def find_every(options)
        set_prefix_to_list_all_locations do
          prefix_options, query_options = split_options(options[:params])
          path = collection_path(prefix_options, query_options)
          instantiate_collection((format.decode(connection.get(path, headers).body) || []), query_options, prefix_options)
        rescue ActiveResource::ResourceNotFound
          # Swallowing ResourceNotFound exceptions and return nil - as per
          # ActiveRecord.
          set_prefix_to_add
          nil
        end
      end
    end
    
    def id_from_response(response)
      JSON.parse(response.body).dig("address", "id")
    rescue JSON::ParserError
      nil
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shiprocket_api-0.4.4 lib/shiprocket_api/resources/pickup_location.rb
shiprocket_api-0.4.3 lib/shiprocket_api/resources/pickup_location.rb
shiprocket_api-0.4.2 lib/shiprocket_api/resources/pickup_location.rb
shiprocket_api-0.4.1 lib/shiprocket_api/resources/pickup_location.rb
shiprocket_api-0.4.0 lib/shiprocket_api/resources/pickup_location.rb