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

#extract_error_body, #extract_error_message, #parse_response, #request

Constructor Details

#initialize(attrs = {}, client) ⇒ Order

Returns a new instance of Order.



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

def initialize(attrs = {}, client)
  @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"]
  @conn = client.conn
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



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

def conn
  @conn
end

#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:



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

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



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

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