steam-trade 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34bdbd304683a4b23f616f4b8ebfb86f05c6a5f5
4
- data.tar.gz: 0af0c76c9407399eaec724220221219bba88382b
3
+ metadata.gz: 404b1b0e1b292caf96982ace83d1ff76f89f3b0e
4
+ data.tar.gz: 8fe1386619ccff5c5a070fd6f288f00b4b9dfefd
5
5
  SHA512:
6
- metadata.gz: c44ba8afd2b5441d8b52b039ef7260473e11a6a23116021073dbd6c260132c8bfe0b856efce97ccc1446bb874c30666c9acd04df9ddba804c7c27b0b790d082f
7
- data.tar.gz: f8f65ea446d9a23a221aad67baa992ea0d5805df846ad1ff5920eb972128d7f094d54650637290ad82b6937b2fbf352e70f36494a0534b506ebeeb2a1ba7cb8d
6
+ metadata.gz: 4bd56dbd81304329324d0bfb95d9c96fabdd4352f4f38287a1420d8e679b7c4fa492a9647b7cc6b67f67be87074511ce0551db7f20f947f36d3b2538b207290e
7
+ data.tar.gz: d22b417c694361138746a5bc0edc93bfb537d955983d584fc88d81f267748d13977a02a602f18f8d0d4e653081e889b624e8c02901e2a8ba0836313102640f27
data/README.md CHANGED
@@ -29,11 +29,10 @@ account.mobile_info('identity_secret')
29
29
 
30
30
  ```
31
31
  ## Getting someone's inventory
32
- #### `normal_get_inventory('steamid','inventoryappid','contextid')`
32
+ #### `normal_get_inventory('steamid','inventoryappid')`
33
33
  - `steamid` is the target's steamid
34
- - `inventoryappid` is the inventory type you want to load, ex : normal inventory(the one which holds trading cards), it's is 753
35
- - `contextid` required to make a correct request to steam servers, ex:for normal inventory(the one which holds trading cards), it's is 6
36
- - if you call `normal_get_inventory()` with no params, it will be default use the current logged-in account `steamid`, `inventoryappid = 753` and `contextid = 6`
34
+ - `inventoryappid` is the inventory type you want to load, `ex : normal inventory(the one which holds trading cards), it's is 753`
35
+ - if you call `normal_get_inventory()` with no params, it will be default use the current logged-in account `steamid`, `inventoryappid = 753`
37
36
 
38
37
  ```ruby
39
38
  require 'steam-trade'
@@ -43,7 +42,9 @@ account.mobile_info('identity_secret')
43
42
 
44
43
  my_inventory = normal_get_inventory() #if you are logged in you can call this command with no parameters to get the logged account's inventory
45
44
 
46
- partner_inventory = normal_get_inventory('76561198044170935')
45
+ partner_inventory = normal_get_inventory('76561198044170935') using steamid
46
+ partner_inventory = normal_get_inventory('https://steamcommunity.com/tradeoffer/new/?partner=410155236&token=H-yK-GFt') #using trade link
47
+ partner_inventory = normal_get_inventory('76561198044170935',)
47
48
  ```
48
49
  the returned items from `normal_get_inventory()` are in the form of an array example : `[item1,item2,item3...itemN]`.
49
50
 
@@ -52,7 +53,15 @@ each item is a hash which contains information about the item in the form of `{"
52
53
  `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.
53
54
 
54
55
  `name` key gives you the item name.
55
- ####
56
+ #### `set_inventory_cache()`
57
+ `set_inventory_cache()` is:
58
+
59
+ - a switch to locally save each inventory you get to a local file.
60
+ - disabled by default, you need to initiate it by calling the command
61
+ - accepts a parameter `timer` which defaults to `timer = 120`, this parameter is the difference between the save file was created and the moment it was checked (upong trying to retrieve the inventory).
62
+
63
+ - this switch is useful if you are getting a "static" inventory or testing your code.
64
+
56
65
 
57
66
  **IMPORTANT**: `normal_get_inventory()` will load the whole target inventory, for each **5k** of items, you are adding **~40MB** to your memory and of course will affect performance of the code and the computer
58
67
  ## Sending a trade offer
@@ -1,13 +1,19 @@
1
1
  module BadgeCommands
2
2
 
3
3
  def sets_count(steamid = @steamid, use_nonmarketable = true)
4
-
5
-
6
4
  if steamid == nil
7
5
  output "no steamid specified"
8
6
  return
9
7
  end
10
8
 
9
+ if [TrueClass,FalseClass].include?(steamid.class) && @steamid != nil
10
+ use_nonmarketable = steamid
11
+ steamid = @steamid
12
+ elsif [TrueClass,FalseClass].include?(steamid.class) && @steamid == nil
13
+ raise "You are not logged in and did not specify a steamid"
14
+ end
15
+
16
+ steamid = verify_profileid_or_trade_link_or_steamid(steamid)
11
17
  thread = Thread.new(steamid) { |steamid| ##getting name
12
18
  targetname = ''
13
19
  begin
@@ -49,7 +55,7 @@ module BadgeCommands
49
55
  end
50
56
  }
51
57
 
52
- bigdata = JSON.parse(File.read("#{@libdir}/blueprints/byappid.json",:external_encoding => 'utf-8',:internal_encoding => 'utf-8'))
58
+ bigdata = JSON.parse(File.read("#{@libdir}blueprints/byappid.json",:external_encoding => 'utf-8',:internal_encoding => 'utf-8'))
53
59
  counted = {}
54
60
 
55
61
  sorted.each { |appid,cards|
@@ -90,8 +96,8 @@ module BadgeCommands
90
96
  filename = persona
91
97
  end
92
98
 
93
- "./#{filename}_badges.txt"
94
- titles = JSON.parse(File.read("#{@libdir}/blueprints/appid_title.json",:external_encoding => 'utf-8',:internal_encoding => 'utf-8'))
99
+
100
+ titles = JSON.parse(File.read("#{@libdir}blueprints/appid_title.json",:external_encoding => 'utf-8',:internal_encoding => 'utf-8'))
95
101
  eachappidsets = eachappidsets.sort_by do |k,v|
96
102
  v
97
103
  end
@@ -4,23 +4,52 @@ module InventoryCommands
4
4
 
5
5
 
6
6
 
7
- def normal_get_inventory(steamid = @steamid ,appid = 753,context = 6)
7
+ def normal_get_inventory(steamid = @steamid ,appid = 753)
8
8
  if steamid == nil
9
- output "no steamid specified"
10
- return
11
- elsif steamid.to_i == 0 && steamid.include?("?partner=") ##supplied trade link
12
- partner_raw = steamid.split('partner=',2)[1].split('&',2)[0]
13
- steamid = partner_id_to_steam_id(partner_raw)
9
+ raise "not logged-in and no steamid specified"
14
10
  end
15
-
11
+
12
+
13
+ appid = appid.to_s
14
+ context = 6
15
+
16
+ #verify given appid only
17
+ if (3..6).to_a.include?(steamid.to_i.to_s.length)
18
+ puts "we got an appid"
19
+ raise "You cannot give an appid only if you are not logged in" if @steamid == nil
20
+ appid = steamid.to_s
21
+ steamid = @steamid
22
+ end
23
+ # end given appid only
24
+
25
+ #verify given another game
26
+ if appid.to_s != "753"
27
+ puts "getting a new game"
28
+ context = 2
29
+ end
30
+ #end verify given another game
31
+ # end verify given appid only
32
+ #verify trade link
33
+
34
+
35
+ steamid = verify_profileid_or_trade_link_or_steamid(steamid)
36
+
37
+ raise "invalid steamid : #{steamid}, length of received :: #{steamid.to_s.length}, normal is 17" if steamid.to_s.length != 17
38
+ ## verify appid
39
+ if ["753","730",'570','440'].include?(appid.to_s) == false
40
+ allgames = JSON.parse(File.read("#{@libdir}blueprints/game_inv_list.json"))
41
+ raise "invalid appid: #{appid}" if allgames.include?(appid.to_s) == false
42
+ end
43
+ ## end verify appid
16
44
 
17
45
  if @inventory_cache == true
18
- verdict = verify_inventory_cache(steamid)
46
+ verdict = verify_inventory_cache(steamid,appid)
19
47
  if verdict != false
20
48
  return verdict
21
49
  end
22
50
  end
23
-
51
+ puts "steamid :#{steamid}"
52
+ puts "appid : #{appid}"
24
53
 
25
54
  items = []
26
55
  last_id = 0
@@ -34,7 +63,7 @@ module InventoryCommands
34
63
 
35
64
  output "total loaded #{items.length} asset"
36
65
  if @inventory_cache == true
37
- File.open("./#{steamid}.inventory", 'w') {|f| f.puts items.to_json}
66
+ File.open("./#{steamid}_#{appid}.inventory", 'w') {|f| f.puts items.to_json}
38
67
  end
39
68
 
40
69
  return items
@@ -47,7 +76,11 @@ module InventoryCommands
47
76
  html = open("https://steamcommunity.com/inventory/#{steamid}/#{appid}/#{context}?start_assetid=#{last_id}&count=5000").read
48
77
 
49
78
  get = JSON.parse(html)
50
-
79
+ raise "something totally unexpected happened while getting inventory with appid #{appid} of steamid #{steamid} with contextid #{context}" if get.key?("error") == true
80
+ if get["total_inventory_count"] == 0
81
+ output "EMPTY :: inventory with appid #{appid} of steamid #{steamid} with contextid #{context}"
82
+ return {'assets' => [], 'new_last_id' =>false}
83
+ end
51
84
  if get.keys[3].to_s == "last_assetid"
52
85
 
53
86
  new_last_id = get.values[3].to_s
@@ -68,7 +101,7 @@ module InventoryCommands
68
101
  }
69
102
 
70
103
  assets.each { |asset| ## merging assets with names
71
- classidxinstane = asset["classid"] + '_' + asset["instanceid"]
104
+ classidxinstance = asset["classid"] + '_' + asset["instanceid"]
72
105
  asset.replace(asset.merge(descriptions_classids[classidxinstance]))
73
106
  }
74
107
 
@@ -81,25 +114,25 @@ module InventoryCommands
81
114
 
82
115
 
83
116
 
84
- def verify_inventory_cache(steamid)
85
- if File.exists?("./#{steamid}.inventory") == false
117
+ def verify_inventory_cache(steamid,appid)
118
+ if File.exists?("./#{steamid}_#{appid}.inventory") == false
86
119
  return false
87
120
  end
88
- puts File.mtime("./#{steamid}.inventory").to_s
121
+ puts File.mtime("./#{steamid}_#{appid}.inventory").to_s
89
122
  puts Time.now.to_s
90
- file_last_time = Time.parse(File.mtime("./#{steamid}.inventory").to_s)
123
+ file_last_time = Time.parse(File.mtime("./#{steamid}_#{appid}.inventory").to_s)
91
124
  current_time = Time.parse(Time.now.to_s)
92
125
  calcule = current_time - file_last_time
93
126
  puts "difference #{calcule}"
94
127
  if calcule.to_i > @inventory_validity
95
- File.delete("./#{steamid}.inventory")
128
+ File.delete("./#{steamid}_#{appid}.inventory")
96
129
  return false
97
130
  else
98
131
  output "gonna use cached inventory which is #{calcule} seconds old"
99
132
  begin
100
- return JSON.parse(File.read("./#{steamid}.inventory",:external_encoding => 'utf-8',:internal_encoding => 'utf-8'))
133
+ return JSON.parse(File.read("./#{steamid}_#{appid}.inventory",:external_encoding => 'utf-8',:internal_encoding => 'utf-8'))
101
134
  rescue
102
- File.delete("./#{steamid}.inventory")
135
+ File.delete("./#{steamid}_#{appid}.inventory")
103
136
  return false
104
137
  end
105
138
  end
@@ -34,8 +34,9 @@ module LoginCommands
34
34
  if response["success"] == true
35
35
  repeater = true
36
36
  elsif repeater == 3
37
- raise "Login failed username: #{@username}, password: #{@password} tried 3 times"
37
+ raise "Login failed username: #{@username}, password: #{@password}, shared_scret: #{@secret} tried 3 times"
38
38
  else
39
+ print repsonse
39
40
  puts "re-trying to login"
40
41
  puts "sleeping for 6 seconds"
41
42
  sleep(6)
@@ -67,6 +67,30 @@ module MiscCommands
67
67
  puts "#{time} :: #{message}"
68
68
  end
69
69
 
70
+ def verify_profileid_or_trade_link_or_steamid(steamid)
71
+ if steamid.to_i == 0 && steamid.include?("?partner=") ##supplied trade link
72
+ puts "got trade link"
73
+ partner_raw = steamid.split('partner=',2)[1].split('&',2)[0]
74
+ steamid = partner_id_to_steam_id(partner_raw)
75
+ return steamid
76
+ elsif steamid.to_i == 0
77
+ puts "got profileid"
78
+ parser = Nokogiri::XML(@session.get("https://steamcommunity.com/id/#{steamid}?xml=1").content)
79
+ if parser.xpath('//error').text == ('The specified profile could not be found.')
80
+ raise "No profile with #{steamid} as profileid"
81
+ end
82
+ steamid = parser.xpath('//steamID64').text
83
+ return steamid
84
+ elsif steamid.to_s.length == 17
85
+ return steamid
86
+ else
87
+ raise "invalid steamid : #{steamid}, length of received :: #{steamid.to_s.length}, normal is 17" if steamid.to_s.length != 17
88
+ end
89
+ end
90
+
91
+
92
+
93
+
70
94
 
71
95
 
72
96
  end
@@ -0,0 +1 @@
1
+ ["777010","614910","603750","562430","308080","270880","530700","290340","489940","740120","411480","485610","296300","238460","650580","550650","531960","529840","581160","429780","615050","397900","302670","544840","730","447820","346930","274940","663920","322330","570","374670","417860","227300","391240","364640","486780","571740","431240","369990","433850","581740","679990","433530","374280","560080","520530","348670","744760","363360","513510","295110","232090","731640","420900","534210","516940","749830","323850","4920","471550","643270","218620","578080","238960","321360","508710","338170","764030","708940","517710","328070","663690","270450","252490","244930","366440","464350","496960","530300","590790","528970","244850","207140","381250","753","250820","264710","321400","440","437220","793720","757160","676340","654700","304930","655010","749820","431960","230410","263920","771950","722670"]
@@ -1,4 +1,4 @@
1
1
  module Meta
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  GEM_NAME = "steam-trade"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steam-trade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - OmG3r
@@ -83,6 +83,7 @@ files:
83
83
  - lib/Trade.rb
84
84
  - lib/blueprints/appid_title.json
85
85
  - lib/blueprints/byappid.json
86
+ - lib/blueprints/game_inv_list.json
86
87
  - lib/meta/version.rb
87
88
  - lib/steam-trade.rb
88
89
  - steam-trade.gemspec