Class: UTApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/utapi/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, password, hash, platform) ⇒ Client

Returns a new instance of Client.



14
15
16
17
# File 'lib/utapi/client.rb', line 14

def initialize(email, password, hash, platform)
  @account = Account.new(email: email, password: password, hash: hash, platform: platform)
  @logged_in = false
end

Instance Attribute Details

#logged_inObject (readonly)

Returns the value of attribute logged_in.



12
13
14
# File 'lib/utapi/client.rb', line 12

def logged_in
  @logged_in
end

Instance Method Details

#auction_status(ids) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/utapi/client.rb', line 37

def auction_status(ids)

  action = 'trade/status?' +  Util.encode_query_string(tradeIds: ids.join(','))

  do_request(action).tap do |response|
    raise ApiCallFailed, "response has no auctionInfo: #{response}" unless response.is_a?(Hash) and response.has_key?('auctionInfo')
  end

end

#bid(trade_id, value) ⇒ Object



47
48
49
50
# File 'lib/utapi/client.rb', line 47

def bid(trade_id, value)
  response = do_request("trade/#{trade_id}/bid", :put, {bid: value})
  response.is_a?(Hash) and response.has_key?('auctionInfo')
end

#delete_from_trade_pile(trade_id) ⇒ Object



90
91
92
# File 'lib/utapi/client.rb', line 90

def delete_from_trade_pile(trade_id)
  do_request("trade/#{trade_id}", :delete)
end

#delete_from_watch_list(*trade_ids) ⇒ Object



94
95
96
97
# File 'lib/utapi/client.rb', line 94

def delete_from_watch_list(*trade_ids)
  action = 'watchlist?' +  Util.encode_query_string(tradeId: trade_ids.join(','))
  do_request(action, :delete)
end

#get_creditsObject



99
100
101
# File 'lib/utapi/client.rb', line 99

def get_credits
  do_request('user/credits')
end

#list_item(item_id, start_price, bin_price, duration) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/utapi/client.rb', line 53

def list_item(item_id, start_price, bin_price, duration)

  response = do_request('auctionhouse', :post, {
      startingBid: start_price,
      duration: duration,
      itemData: {
          id: item_id
      },
      buyNowPrice: bin_price
  })

  response.is_a?(Hash) and response.has_key?('id')
end

#loginObject



19
20
21
22
23
24
25
# File 'lib/utapi/client.rb', line 19

def 
  @authorization = generate_authorization
rescue LoginError
  false
else
  true
end

#move_card(item_id, pile) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/utapi/client.rb', line 67

def move_card(item_id, pile)

  response = do_request('item', :put, {
      itemData: [{ id: item_id, pile: pile }]
  })

  response.is_a?(Hash) and response.has_key?('itemData') and response['itemData'][0]['success']
end

#search(params) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/utapi/client.rb', line 27

def search(params)

  action = 'transfermarket?' + Util.encode_query_string(params)

  do_request(action).tap do |response|
    raise ApiCallFailed, "response has no auctionInfo: #{response}" unless response.is_a?(Hash) and response.has_key?('auctionInfo')
  end

end

#trade_pileObject



76
77
78
79
80
# File 'lib/utapi/client.rb', line 76

def trade_pile
  do_request('tradepile', :get).tap do |response|
    raise ApiCallFailed, "Cannot get trade pile, response: #{response}" unless response.is_a?(Hash) and response.has_key?('auctionInfo')
  end
end

#unassigned_itemsObject



86
87
88
# File 'lib/utapi/client.rb', line 86

def unassigned_items
  do_request('purchased/items', :get)
end

#watch_listObject



82
83
84
# File 'lib/utapi/client.rb', line 82

def watch_list
  do_request('watchlist', :get)
end