Class: ProxyCheapClient::Order

Inherits:
Base
  • Object
show all
Defined in:
lib/proxy_cheap_client/models/order.rb

Overview

module Models

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#conn, extract_error_body, extract_error_message, parse_response, request, #request

Constructor Details

#initialize(attrs) ⇒ Order

:currency,



12
13
14
15
16
17
18
19
20
# File 'lib/proxy_cheap_client/models/order.rb', line 12

def initialize(attrs)
  @data = attrs
  @id = attrs["id"] || attrs["orderId"]
  #@status = attrs["status"]
  #@proxies = attrs["proxies"]
  #@created_at = attrs["createdAt"] || attrs["created_at"]
  @total_price = attrs["totalPrice"] || attrs["total_price"]
  #@currency = attrs["currency"]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/proxy_cheap_client/models/order.rb', line 4

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/proxy_cheap_client/models/order.rb', line 4

def id
  @id
end

#total_priceObject (readonly)

Returns the value of attribute total_price.



4
5
6
# File 'lib/proxy_cheap_client/models/order.rb', line 4

def total_price
  @total_price
end

Instance Method Details

#proxiesOrder

Get proxies of an order

Parameters:

  • order_id (String)

    Order ID

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/proxy_cheap_client/models/order.rb', line 36

def proxies()
    order_id = self.id
    resp = request(:get, "orders/#{order_id}/proxies")

    # The response may be an array or wrapped in a key (e.g. "proxies" or "data").
    proxy_data = if resp.is_a?(Hash) && resp.key?("proxies")
          resp["proxies"]
        elsif resp.is_a?(Hash) && resp.key?("data")
          resp["data"]
        else
          resp
        end

    Array(proxy_data).map { |p| ProxyCheapClient::Proxy.new(p) }
end

#to_hObject

initialize



22
23
24
25
26
27
28
29
30
31
# File 'lib/proxy_cheap_client/models/order.rb', line 22

def to_h
  {
    id: id,
    #status: status,
    #proxies: proxies,
    #created_at: created_at,
    total_price: total_price,
    #currency: currency
  }
end