steam-trade 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 821dfc0b7359db3a2119a930ca53b13a543634d4
4
- data.tar.gz: 20e4fcdf9864d781083a9fa6360927bc1593e341
3
+ metadata.gz: 8e65c68cce7672c15f8bc79fabbbdff115f458a3
4
+ data.tar.gz: 49ef4f902b97621dba4c2b3825584b0079bf5aff
5
5
  SHA512:
6
- metadata.gz: 07ce8d290f7ebc8ebd3cae55984b896c8f2b6970c9c577e3428a732bd35b17250e2df40fd18a8709610858205066cd7c475a28a6c4efb26824bcf51fe684b97b
7
- data.tar.gz: f671b05935a3c504ee86ad53f4cf5c4bc95fc4fce5eb326d6a2d8a361abce98bba7fbf172ad1b899a206c8bbcc9517a344c7646933b77b9c8a04d91766385344
6
+ metadata.gz: 6eb0c8f83eb83c7a80833b44dbf8e20a72b898fe0cf0b95278562448785bac166c0f2e0acfe15bfd629f81bae1fce31f55741cb2637aae5f7041e41f7e8d1f47
7
+ data.tar.gz: cd414d6caa1f967dc653b6e0c3858b8889f28f8f5132ef8399b0dccd2b3d21711c6a8c944ce21fb95035903aa6ef18e5e9d5f823feaf1be00adc7d7266c4c402
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # steam-trade V0.0.9
1
+ # steam-trade V0.1.1
2
+ Please check constantly for updates cause i'm still making this gem.
2
3
 
3
4
  This gem simplifes/allows sending steam trade offers programmatically.
4
5
 
@@ -8,10 +9,26 @@ this gem is primarly for trading cards, tho can be used to CS:GO and other games
8
9
  - [Installation](#installation)
9
10
  - [Usage & Examples](#usage)
10
11
  - [Logging-in](#logging-in)
12
+ - [Hander.new() (this is how you login)](#handlernewusername-passwordshared_secret)
13
+ - [mobile_info()](#mobile_infoidentity_secret)
11
14
  - [Getting someone's inventory](#getting-someones-inventory)
15
+ - [normal_get_inventory()](#normal_get_inventorysteamidinventoryappid)
16
+ - [raw_get_inventory()](#raw_get_inventorytargetinventoryappidtrimming)
17
+ - [set_inventory_cache()](#set_inventory_cache)
12
18
  - [Sending a trade offer](#sending-a-trade-offer)
19
+ - [send_offer()](#send_offermyarraytheirarraytrade_offer_linkmessage)
20
+ - [Handling Trade Offers](#handling-trade-offers)
21
+ - [set_api_key()](#set_api_keyapi_key)
22
+ - [get_trade_offers()](#get_trade_offerstime)
23
+ - [get_trade_offer()](#get_trade_offertrade_offer_id)
24
+ - [accept_trade_offer()](#accept_trade_offertrade_offer_id)
25
+ - [decline_trade_offer()](#decline_trade_offertrade_offer_id)
26
+ - [cancel_trade_offer()](#cancel_trade_offertrade_offer_id)
13
27
  - [Counting badges owned](#counting-badges-owned)
28
+ - [sets_count()](#sets_counttargetnon_marketable)
14
29
  - [2FA codes](#2fa-codes)
30
+ - [fa()](#fashared_secret)
31
+ - [More commands](#more-commands)
15
32
 
16
33
  ## Installation
17
34
  in your commandline :
@@ -24,17 +41,13 @@ First you need to require the gem:
24
41
  require 'steam-trade'
25
42
  ```
26
43
  ## Logging-in
44
+ #### `Handler.new(username, password,shared_secret)`
27
45
  then you need to login and optionally set your shared_secret and identity_secret:
28
46
  - `shared_secret` is used to generate steam authentication codes so you won't have to write them manually each time you login.
29
- - `identity_secret` is used to confirm trade offers automatically.
30
47
  ```ruby
31
48
  require 'steam-trade'
32
49
 
33
50
  account = Handler.new('username','password','shared_secret') # share secret is optional
34
- #username and password are required, shared_secret is optional
35
-
36
- account.mobile_info('identity_secret')
37
- #identity_secret is required
38
51
 
39
52
  ##########
40
53
  account = Handler.new('username') #this of course counts as non logged in
@@ -48,7 +61,18 @@ account = Handler.new()
48
61
  puts account.fa('v3dWNq2Ncutc7RelwRVXswT8CJX=v3dWNq2Ncutc7WelwRVXswT8CJk=') => random code
49
62
 
50
63
  ```
64
+ #### `mobile_info(identity_secret)`
65
+ - `identity_secret` is your account's identity secret (try using google if you don't know what this is).
66
+ - `identity_secret` is used to automatically confirm trade offers.
67
+ ```ruby
68
+ require 'steam-trade'
69
+
70
+ account = Handler.new('username','password','shared_secret')
71
+ account.mobile_info('identity_secret')
72
+ ```
73
+
51
74
  ## Getting someone's inventory
75
+ you might want to read this [guide](https://dev.doctormckay.com/topic/332-identifying-steam-items/)
52
76
  #### `normal_get_inventory('steamid','inventoryappid')`
53
77
  - `steamid` is the target's steamID, or profileID, or trade link
54
78
  - `inventoryappid` is the inventory type you want to load, `ex : normal inventory(the one which holds trading cards), it's is 753`
@@ -89,6 +113,46 @@ each item is a hash which contains information about the item in the form of `{"
89
113
  `market_fee_app` key gives you the appid of the game's app (for trading cards), for other items technically `inventoryappid` is the games appid.
90
114
 
91
115
  `name` key gives you the item name.
116
+ #### `raw_get_inventory(target,inventoryappid,trimming)`
117
+ **IMPORTANT**: this command efficiency is better than `normal_get_inventory`, therefore i **recommend** using this one.
118
+ - `target` is a steamID/profileID/trade link
119
+ - `inventoryappid` is the inventory type you want to load, `ex : normal inventory(the one which holds trading cards), it's is 753`
120
+ - `trimming`, defaults to `true` this will remove images link and steam-server-side related informations from the descriptions hash, drastically reducing the size of data received.
121
+
122
+ This command will return a hash nearly identitical to the one received from steam the hash will have 2 keys `assets` and `descriptions`:
123
+ - `assets` has an array as value, identical to steam's [(example)](https://steamcommunity.com/inventory/76561198044170935/753/6?start_assetid=0&count=100)
124
+ - `descriptions` has an array as a value identical to steam's [(example)](https://steamcommunity.com/inventory/76561198044170935/753/6?start_assetid=0&count=100)
125
+
126
+ ```ruby
127
+ require 'steam-trade'
128
+ logged = Handler.new('username','password','shared_secret')
129
+ inv = logged.raw_get_inventory() #works
130
+ inv = logged.raw_get_inventory(false) # returns non trimmed
131
+ inv = logged.raw_get_inventory(440) #works
132
+ inv = logged.raw_get_inventory(76561198044170935,false) #works
133
+ inv = logged.raw_get_inventory(76561198044170935,440) # works
134
+
135
+ print inv['assets'] will print all the assets
136
+ print inv['descriptions'] will print all the descriptions
137
+
138
+ ### how to accurately use this
139
+
140
+ class_instance = {}
141
+ ## map all the items
142
+ inv['descriptions'].each { |desc|
143
+ identifier = desc['classid'] + '_' + desc['instanceid']
144
+ class_instance[identifier] = desc
145
+ }
146
+
147
+ ## identify your items
148
+
149
+ inv['assets'].each { |asset|
150
+ identifier = asset['classid'] + '_' + asset['instanceid']
151
+ puts class_instance[identifier] this will output the item's description
152
+ }
153
+
154
+ ```
155
+
92
156
  #### `set_inventory_cache()`
93
157
  `set_inventory_cache()` is:
94
158
 
@@ -145,6 +209,117 @@ account.send_offer(myarray,theirarray,'76561198370420964',message)
145
209
  # whenever
146
210
  account.send_offer(myarray,theirarray,"https://steamcommunity.com/tradeoffer/new/?partner=410155236&token=H-yK-GFt",message)
147
211
 
212
+ ```
213
+ ## Handling Trade Offers
214
+ you might want to read [Steam Trading API](https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService)
215
+
216
+ **ALL OF THE COMMANDS BELOW REQUIRE AN API_KEY**
217
+
218
+ #### `set_api_key(API_KEY)`
219
+ **NOTE**:If you are using a **logged in** Handler there is no need to set the API_KEY.
220
+ - `API_KEY` is your apikey, you can get that from [here](https://steamcommunity.com/dev/apikey).
221
+ ```ruby
222
+ require 'steam-trade'
223
+ acc = Handler.new()
224
+ trade_offers = acc.get_trade_offers() # will raise an exception
225
+ acc.set_api_key('mykey')
226
+ trade_offers = acc.get_trade_offers() # after setting an API_KEY this will succeed
227
+ ```
228
+ #### `get_trade_offers(time)`
229
+ - `time` is the moment from which you want to get updates (explained in the example)
230
+ this will return a hash with `trade_offers_sent`, `trade_offers_received`, `descriptions` as keys.
231
+ `descriptions` includes the descriptions of all items returned from `trade_offers_sent` or `trade_offers_received`
232
+
233
+ ```ruby
234
+ require 'steam-trade'
235
+ logged = Handler.new('username','password','shared_secret')
236
+ logged.mobile_info('identity_secret')
237
+
238
+ time = '' # this is the initial check for offers so we want them all
239
+ polling = Thread.new(logged) { |logged|
240
+ loop do
241
+ offers = logged.get_trade_offers(time)
242
+ time = Time.new.to_i # we save the time of the last check
243
+ next if offers['trade_offers_received'] == nil # do nothing, if there is no trades
244
+ puts offers['trade_offers_received'] # puts the trades
245
+ sleep(15) # make sure not to spam steam's server or they will block list your IP for a period of time therefore you can't make requests
246
+ end
247
+ }
248
+ ```
249
+ #### `get_trade_offer(trade_offer_id)`
250
+ gets more information about a specific trade offer
251
+ - `trade_offer_id` is the id of the offer you want to confirm (you can get the id using [this](#get_trade_offerstime) to get the offerID
252
+
253
+ have no example how to actually use this cause `get_trade_offers(time)` is probably better
254
+
255
+ #### `accept_trade_offer(trade_offer_id)`
256
+ - `trade_offer_id` is the id of the offer you want to confirm (you can get the id using [this](#get_trade_offerstime) to get the offerID
257
+ ```ruby
258
+ require 'steam-trade'
259
+ logged = Handler.new('username','password','shared_secret')
260
+ logged.mobile_info('identity_secret')
261
+
262
+ time = '' # this is the initial check for offers so we want them all
263
+ polling = Thread.new(logged) { |logged|
264
+ loop do
265
+ offers = logged.get_trade_offers(time)
266
+ time = Time.new.to_i # we save the time of the last check
267
+ next if offers['trade_offers_received'] == nil # do nothing, if there is no trades
268
+ offers['trade_offers_received'].each { |trade|
269
+ if trade['accountid_other'].to_i == 83905207 ## this will accept all trade received from 83905207 (Steam32 ID)
270
+ logged.accept_trade_offer(trade['tradeofferid']) # to accept the trade
271
+ end
272
+ }
273
+ sleep(15) # make sure not to spam steam's server or they will block list your IP for a period of time therefore you can't make requests
274
+ end
275
+ }
276
+ ```
277
+ #### `decline_trade_offer(trade_offer_id)`
278
+ this declines a trade offer you **RECEIVED**
279
+ - `trade_offer_id` is the id of the offer you want to confirm (you can get the id using [this](#get_trade_offerstime) to get the offerID
280
+
281
+ ```ruby
282
+ require 'steam-trade'
283
+ logged = Handler.new('username','password','shared_secret')
284
+ logged.mobile_info('identity_secret')
285
+
286
+ time = '' # this is the initial check for offers so we want them all
287
+ polling = Thread.new(logged) { |logged|
288
+ loop do
289
+ offers = logged.get_trade_offers(time)
290
+ time = Time.new.to_i # we save the time of the last check
291
+ next if offers['trade_offers_received'] == nil # do nothing, if there is no trades
292
+ offers['trade_offers_received'].each { |trade| # we need to check received offers to use 'decline'
293
+ if trade['accountid_other'].to_i != 83905207 ## notice the '!='
294
+ logged.decline_trade_offer(trade['tradeofferid']) # decline the trade
295
+ end
296
+ }
297
+ sleep(15) # make sure not to spam steam's server or they will block list your IP for a period of time therefore you can't make requests
298
+ end
299
+ }
300
+ ```
301
+ #### `cancel_trade_offer(trade_offer_id)`
302
+ this cancels a trade offer you **SENT**
303
+ - `trade_offer_id` is the id of the offer you want to confirm (you can get the id using [this](#get_trade_offerstime) to get the offerID
304
+ ```ruby
305
+ require 'steam-trade'
306
+ logged = Handler.new('username','password','shared_secret')
307
+ logged.mobile_info('identity_secret')
308
+
309
+ time = '' # this is the initial check for offers so we want them all
310
+ polling = Thread.new(logged) { |logged|
311
+ loop do
312
+ offers = logged.get_trade_offers(time)
313
+ time = Time.new.to_i # we save the time of the last check
314
+ next if offers['trade_offers_sent'] == nil # do nothing, if there is no trades
315
+ offers['trade_offers_sent'].each { |trade| # we need to check sentoffers to use 'cancel'
316
+ if trade['accountid_other'].to_i != 83905207 ## notice the '!='
317
+ logged.cancel_trade_offer(trade['tradeofferid']) # cancel the trade
318
+ end
319
+ }
320
+ sleep(15) # make sure not to spam steam's server or they will block list your IP for a period of time therefore you can't make requests
321
+ end
322
+ }
148
323
  ```
149
324
  ## Counting badges owned
150
325
  #### `sets_count(target,non_marketable)`
@@ -201,7 +376,8 @@ puts nonlogged.fa() # will not work
201
376
  puts logged.fa() # will give a random code
202
377
 
203
378
  ```
204
-
379
+ ## More commands
380
+ you can find more non-vital commands in the [wiki](https://github.com/OmG3r/steam-trade/wiki)
205
381
  ## License
206
382
 
207
383
  The gem is available as open source under the terms of the [GNU GPLV3](https://github.com/OmG3r/steam-trade/blob/master/LICENSE).
@@ -114,35 +114,30 @@ module BadgeCommands
114
114
  v
115
115
  end
116
116
  eachappidsets.reverse!
117
- begin
118
- File.truncate("./#{filename}_badges.txt", 0)
119
- rescue
120
- end
121
117
  output "Writing the badges to #{filename}_badges.txt "
122
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts "for #{persona}(#{steamid})"}
118
+ text = []
119
+ text << "for #{persona}(#{steamid})"
123
120
  if use_nonmarketable == false
124
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts "total non-foil trading cards #{total_non_foil}"}
125
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts "only marketable cards are counted"}
121
+ text << "only marketable cards are counted"
122
+ text << "total non-foil trading cards #{total_non_foil}"
126
123
  else
127
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts "total non-foil trading cards #{total_non_foil}"}
128
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts "all cards counted including non-marketable"}
124
+ text << "total non-foil trading cards #{total_non_foil}"
125
+ text << "all cards counted including non-marketable"
129
126
  end
130
127
 
131
128
 
132
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts "total sets in target account #{totalsets}"}
133
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts ""}
134
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts ""}
135
-
136
-
129
+ text << "total sets in target account #{totalsets}"
130
+ text << ""
131
+ text << ""
137
132
  eachappidsets.each { |appid, sets|
138
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts "#{titles[appid]}, sets = #{sets}, appid = #{appid}"}
133
+ text << " #{titles[appid]}, sets = #{sets}, appid = #{appid}"
139
134
  hashofcards[appid].each { |cardname, owned|
140
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts "#{cardname} xxx #{owned}"}
135
+ text << "#{cardname} xxx #{owned}"
141
136
  }
142
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts ""}
143
- File.open("./#{filename}_badges.txt",'a+:UTF-8') {|f| f.puts ""}
137
+ text << ""
138
+ text << ""
144
139
  }
145
-
140
+ File.open("./#{filename}_badges.txt",'w:UTF-8') {|f| f.puts text}
146
141
  output "badges.txt has been created"
147
142
  end
148
143
 
@@ -4,10 +4,10 @@ module GuardCommands
4
4
 
5
5
 
6
6
 
7
- def fa(shared_secret = @secret)
7
+ def fa(shared_secret = @secret,time_difference = 0)
8
8
  raise "No shared_secret given" if shared_secret == nil # cause upon initialization @secret = nil
9
- timestamp = Time.new.to_i
10
- math = timestamp / 30
9
+ timestamp = Time.new.to_i + time_difference
10
+ math = timestamp.to_i / 30
11
11
  math = math.to_i
12
12
  time_buffer =[math].pack('Q>')
13
13
 
@@ -45,7 +45,6 @@ module InventoryCommands
45
45
  last_id = received['new_last_id']
46
46
  items = items + received['assets']
47
47
  output "loaded #{items.length}"
48
- sleep(2) if last_id != false
49
48
  end
50
49
 
51
50
  output "total loaded #{items.length} asset"
@@ -154,7 +153,6 @@ module InventoryCommands
154
153
  hash["assets"] = hash["assets"] + received['assets']
155
154
  hash["descriptions"] = hash["descriptions"] + received["descriptions"]
156
155
  output "loaded #{hash["assets"].length}"
157
- sleep(2) if last_id != false
158
156
  end
159
157
 
160
158
  output "total loaded #{hash["assets"].length} asset"
@@ -178,7 +176,7 @@ module InventoryCommands
178
176
  def get_inventory_chunk_normal_way(appid,context,steamid,last_id)
179
177
 
180
178
 
181
- html = open("https://steamcommunity.com/inventory/#{steamid}/#{appid}/#{context}?start_assetid=#{last_id}&count=5000").read
179
+ html = @session.get("https://steamcommunity.com/inventory/#{steamid}/#{appid}/#{context}?start_assetid=#{last_id}&count=5000").content
182
180
 
183
181
  get = JSON.parse(html)
184
182
  raise "something totally unexpected happened while getting inventory with appid #{appid} of steamid #{steamid} with contextid #{context}" if get.key?("error") == true
@@ -224,7 +222,7 @@ module InventoryCommands
224
222
  def get_inventory_chunk_raw_way(appid,context,steamid,last_id,trim)
225
223
 
226
224
 
227
- html = open("https://steamcommunity.com/inventory/#{steamid}/#{appid}/#{context}?start_assetid=#{last_id}&count=5000").read
225
+ html = @session.get("https://steamcommunity.com/inventory/#{steamid}/#{appid}/#{context}?start_assetid=#{last_id}&count=5000").content
228
226
 
229
227
  get = JSON.parse(html)
230
228
  raise "something totally unexpected happened while getting inventory with appid #{appid} of steamid #{steamid} with contextid #{context}" if get.key?("error") == true
@@ -1,6 +1,7 @@
1
1
  module LoginCommands
2
2
 
3
3
  ########################################################################################
4
+ private
4
5
  def login()
5
6
  data = pass_stamp()
6
7
  encrypted_password = data["password"]
@@ -8,7 +9,7 @@ module LoginCommands
8
9
  repeater = 0
9
10
  until repeater == true
10
11
  if @secret != nil
11
- guardcode = fa()
12
+ guardcode = fa(@secret,@time_difference)
12
13
  else
13
14
  puts "please write your 2FA code"
14
15
  guardcode = gets.chomp
@@ -87,7 +88,6 @@ module LoginCommands
87
88
 
88
89
 
89
90
  ########################################################################################
90
- private
91
91
  def pass_stamp()
92
92
  response = @session.post('https://store.steampowered.com/login/getrsakey/', {'username' => @username})
93
93
 
@@ -44,7 +44,7 @@ module MiscCommands
44
44
  def output(message)
45
45
  time = Time.new
46
46
  add = time.strftime("%d-%m-%Y %H:%M:%S")
47
- puts "#{time} :: #{message}" if @messages == true
47
+ puts "#{add} :: #{message}" if @messages == true
48
48
  end
49
49
 
50
50
  def verify_profileid_or_trade_link_or_steamid(steamid)
@@ -1,4 +1,4 @@
1
1
  module Meta
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  GEM_NAME = "steam-trade"
4
4
  end
@@ -29,12 +29,26 @@ class Handler
29
29
  include PlayerCommands
30
30
  include TradeAPI
31
31
 
32
- def initialize(username = nil ,password = nil,secret = nil)
32
+ def initialize(username = nil ,password = nil,*params)
33
+ raise "can only take 4 params, given #{params.length}" if params.length > 2
33
34
  @loggedin = false # will be set to true once we login
34
35
 
35
36
  @username = username
36
37
  @password = password
37
- @secret = secret
38
+ @secret = nil
39
+ @time_difference = 0
40
+
41
+
42
+ if params.length == 2
43
+ @secret = params[0] if params[0].class == String
44
+ @time_difference = params[1] if params[1].class == Integer
45
+ elsif params.length == 1 && params[0].class == String
46
+ @secret = params[0]
47
+ @time_difference = 0
48
+ elsif params.length == 1 && params[0].class == Integer
49
+ @secret = nil
50
+ @time_difference = params[0]
51
+ end
38
52
 
39
53
  @steamid = nil # will be initialized once you login and can be initialized with mobile_info
40
54
  @identity_secret = nil # can and should be initialized using mobile_info
@@ -43,6 +57,7 @@ class Handler
43
57
  @session = Mechanize.new { |agent| # the session which will hold your cookies to communicate with steam
44
58
  agent.user_agent_alias = 'Windows Mozilla'
45
59
  agent.follow_meta_refresh = true
60
+ agent.history_added = Proc.new {sleep 2}
46
61
  }
47
62
 
48
63
  @inventory_cache = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steam-trade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - OmG3r
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-27 00:00:00.000000000 Z
11
+ date: 2018-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler