backpack_tf 0.8.4 → 1.0.0.rc1

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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -3
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +5 -3
  6. data/Gemfile.lock +49 -0
  7. data/README.md +144 -0
  8. data/Rakefile +7 -0
  9. data/backpack_tf.gemspec +2 -2
  10. data/lib/backpack_tf/assets/{attribute_controlled_attached_particles.json → particle_effects.json} +0 -0
  11. data/lib/backpack_tf/client.rb +72 -95
  12. data/lib/backpack_tf/currency/interface.rb +9 -0
  13. data/lib/backpack_tf/currency/response.rb +24 -0
  14. data/lib/backpack_tf/currency.rb +24 -47
  15. data/lib/backpack_tf/helpers.rb +29 -0
  16. data/lib/backpack_tf/interface.rb +29 -0
  17. data/lib/backpack_tf/market_price/interface.rb +9 -0
  18. data/lib/backpack_tf/market_price/response.rb +15 -0
  19. data/lib/backpack_tf/market_price.rb +25 -0
  20. data/lib/backpack_tf/price/interface.rb +19 -0
  21. data/lib/backpack_tf/price/item.rb +85 -0
  22. data/lib/backpack_tf/price/item_price.rb +113 -0
  23. data/lib/backpack_tf/price/particle_effect.rb +27 -0
  24. data/lib/backpack_tf/price/response.rb +38 -0
  25. data/lib/backpack_tf/price.rb +9 -81
  26. data/lib/backpack_tf/price_history/interface.rb +22 -0
  27. data/lib/backpack_tf/price_history/response.rb +15 -0
  28. data/lib/backpack_tf/price_history.rb +25 -0
  29. data/lib/backpack_tf/response.rb +9 -56
  30. data/lib/backpack_tf/special_item/interface.rb +9 -0
  31. data/lib/backpack_tf/special_item/response.rb +16 -0
  32. data/lib/backpack_tf/special_item.rb +11 -21
  33. data/lib/backpack_tf/user/interface.rb +18 -0
  34. data/lib/backpack_tf/user/response.rb +16 -0
  35. data/lib/backpack_tf/user.rb +10 -19
  36. data/lib/backpack_tf/user_listing/interface.rb +18 -0
  37. data/lib/backpack_tf/user_listing/response.rb +15 -0
  38. data/lib/backpack_tf/user_listing.rb +31 -43
  39. data/lib/backpack_tf/version.rb +1 -1
  40. data/lib/backpack_tf.rb +8 -8
  41. data/spec/backpack_tf/client_spec.rb +151 -101
  42. data/spec/backpack_tf/currency/interface_spec.rb +8 -0
  43. data/spec/backpack_tf/currency/response_spec.rb +41 -0
  44. data/spec/backpack_tf/currency_spec.rb +34 -118
  45. data/spec/backpack_tf/helpers_spec.rb +85 -0
  46. data/spec/backpack_tf/interface_spec.rb +56 -0
  47. data/spec/backpack_tf/market_price/interface_spec.rb +8 -0
  48. data/spec/backpack_tf/market_price/response_spec.rb +22 -0
  49. data/spec/backpack_tf/market_price_spec.rb +22 -0
  50. data/spec/backpack_tf/price/interface_spec.rb +27 -0
  51. data/spec/backpack_tf/price/item_price_spec.rb +101 -0
  52. data/spec/backpack_tf/price/item_spec.rb +291 -0
  53. data/spec/backpack_tf/price/particle_effect_spec.rb +23 -0
  54. data/spec/backpack_tf/price/response_spec.rb +87 -0
  55. data/spec/backpack_tf/price_history/interface_spec.rb +38 -0
  56. data/spec/backpack_tf/price_history/response_spec.rb +22 -0
  57. data/spec/backpack_tf/price_history_spec.rb +24 -0
  58. data/spec/backpack_tf/response_spec.rb +22 -108
  59. data/spec/backpack_tf/special_item/interface_spec.rb +8 -0
  60. data/spec/backpack_tf/special_item/response_spec.rb +26 -0
  61. data/spec/backpack_tf/special_item_spec.rb +23 -100
  62. data/spec/backpack_tf/user/interface_spec.rb +20 -0
  63. data/spec/backpack_tf/user/response_spec.rb +27 -0
  64. data/spec/backpack_tf/user_listing/interface_spec.rb +20 -0
  65. data/spec/backpack_tf/user_listing/response_spec.rb +21 -0
  66. data/spec/backpack_tf/user_listing_spec.rb +53 -81
  67. data/spec/backpack_tf/user_spec.rb +16 -83
  68. data/spec/fixtures/item_price_typical.json +6 -0
  69. data/spec/fixtures/item_price_unusual.json +7 -0
  70. data/spec/fixtures/item_typical.json +1 -1
  71. data/spec/fixtures/item_unusual.json +311 -1
  72. data/spec/fixtures/item_with_dual_craftability_tradability.json +59 -0
  73. data/spec/fixtures/market_prices.json +1 -0
  74. data/spec/fixtures/price_history.json +1 -0
  75. data/spec/fixtures/prices.json +80 -1
  76. data/spec/fixtures/user_listing.json +1 -1
  77. data/spec/fixtures/user_listing_individual.json +51 -0
  78. data/spec/spec_helper.rb +12 -52
  79. metadata +61 -16
  80. data/TODO.md +0 -15
  81. data/lib/backpack_tf/item.rb +0 -84
  82. data/lib/backpack_tf/item_price.rb +0 -172
  83. data/readme.md +0 -96
  84. data/spec/backpack_tf/inherited_class_methods_spec.rb +0 -100
  85. data/spec/backpack_tf/item_price_spec.rb +0 -119
  86. data/spec/backpack_tf/item_spec.rb +0 -126
  87. data/spec/backpack_tf/price_spec.rb +0 -184
  88. data/spec/fixtures/item_without_defindex.json +0 -1
@@ -1,106 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
- module BackpackTF
4
- describe SpecialItem do
5
- let(:bp) { Client.new }
6
-
7
- let(:json_obj) {
8
- fixture = file_fixture('special_items.json')
9
- fixture = JSON.parse(fixture)['response']
10
- Response.hash_keys_to_sym(fixture)
11
- }
12
-
13
- it 'has these default attributes' do
14
- expect(described_class.interface).to eq :IGetSpecialItems
15
- end
16
-
17
- describe '::response' do
18
- before :all do
19
- expect(described_class.response).to be_nil
20
- end
21
-
22
- before :each do
23
- stub_http_response_with('special_items.json')
24
- fetched_special_items = bp.fetch(:special_items)
25
- bp.update(described_class, fetched_special_items)
26
- end
27
-
28
- after :all do
29
- Response.responses(:reset => :confirm)
30
- expect(Response.responses).to be_empty
31
- expect(described_class.response).to be_nil
32
- expect(described_class.items).to be_nil
33
- end
34
-
35
- it 'the keys of the response attribute should have these values' do
36
- response = described_class.response
37
- expect(response[:success]).to eq 1
38
- expect(response[:message]).to eq nil
39
- expect(response[:current_time]).to eq 1431108270
40
- end
41
- end
42
-
43
- describe '::items' do
44
- before :all do
45
- expect(described_class.response).to be_nil
46
- expect(described_class.items).to be_nil
47
- end
48
-
49
- before :each do
50
- Response.responses(:reset => :confirm)
51
- expect(Response.responses).to be_empty
52
-
53
- stub_http_response_with('special_items.json')
54
- fetched_special_items = bp.fetch(:special_items)
55
- bp.update(described_class, fetched_special_items)
56
- end
57
-
58
- after :all do
59
- Response.responses(:reset => :confirm)
60
- expect(Response.responses).to be_empty
61
- described_class.class_eval { @items = nil }
62
- end
63
-
64
- it 'returns the fixture and sets to @@items variable' do
65
- expect(described_class.items).not_to be_nil
66
- end
67
-
68
- it 'is a Hash object' do
69
- expect(described_class.items).to be_instance_of Hash
70
- end
71
-
72
- it 'has these 2 keys' do
73
- expect(described_class.items.keys).to match_array [':weed:', 'Random Craft Hat']
74
- end
75
-
76
- it 'each key points to an instance of SpecialItem' do
77
- expect(described_class.items.values).to all be_a BackpackTF::SpecialItem
78
- end
79
- end
80
-
81
- describe '#initialize' do
82
- let(:some_json) {
83
- JSON.parse(file_fixture 'special_items.json')['response']['items'][1]
84
- }
3
+ describe BackpackTF::SpecialItem do
4
+ let(:json_response) do
5
+ fixture = file_fixture('special_items.json')
6
+ JSON.parse(fixture)['response']
7
+ end
85
8
 
86
- it 'has these attributes' do
87
- special_item = described_class.new('Random Craft Hat', some_json)
88
- expect(special_item).to have_attributes(
89
- :name => 'Random Craft Hat',
90
- :item_name => 'Random Craft Hat',
91
- :defindex => -2,
92
- :item_class => 'tf_wearable',
93
- :item_type_name => 'Currency Item',
94
- :item_description => 'Any item that is considered to be a random craft hat.',
95
- :item_quality => 0,
96
- :min_ilevel => 1,
97
- :max_ilevel => 1,
98
- :image_url => "https:\/\/steamcdn-a.akamaihd.net\/apps\/440\/icons\/kit_fancyhats.bf5ba4ea973728df20402c0c9a4737f18d5d560c.png",
99
- :image_url_large => "https:\/\/steamcdn-a.akamaihd.net\/apps\/440\/icons\/kit_fancyhats_large.800ea1b16df707ffa27f9f6e6033e8ba3f0f5333.png",
100
- :appid => 440
101
- )
102
- end
9
+ describe '#initialize' do
10
+ it 'has these attributes' do
11
+ some_json = json_response['items'][1]
12
+ special_item = described_class.new('Random Craft Hat', some_json)
13
+ expect(special_item).to have_attributes(
14
+ name: 'Random Craft Hat',
15
+ item_name: 'Random Craft Hat',
16
+ defindex: -2,
17
+ item_class: 'tf_wearable',
18
+ item_type_name: 'Currency Item',
19
+ item_description: 'Any item that is considered to be a random craft hat.',
20
+ item_quality: 0,
21
+ min_ilevel: 1,
22
+ max_ilevel: 1,
23
+ image_url: 'https://steamcdn-a.akamaihd.net/apps/440/icons/kit_fancyhats.bf5ba4ea973728df20402c0c9a4737f18d5d560c.png',
24
+ image_url_large: 'https://steamcdn-a.akamaihd.net/apps/440/icons/kit_fancyhats_large.800ea1b16df707ffa27f9f6e6033e8ba3f0f5333.png',
25
+ appid: 440
26
+ )
103
27
  end
104
-
105
28
  end
106
29
  end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::User::Interface do
4
+ it 'has these default attributes' do
5
+ expect(described_class.name).to eq :IGetUsers
6
+ expect(described_class.version).to eq 3
7
+ expect(described_class.steamids).to eq nil
8
+ end
9
+ describe '::defaults' do
10
+ after(:each) do
11
+ described_class.class_eval { @steamids = nil }
12
+ end
13
+
14
+ it 'can modify its values' do
15
+ options = { steamids: [1, 2, 3] }
16
+ described_class.defaults(options)
17
+ expect(described_class.steamids).to eq [1, 2, 3]
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::User::Response do
4
+ let(:json_response) do
5
+ fixture = file_fixture('users.json')
6
+ JSON.parse(fixture)['response']
7
+ end
8
+
9
+ describe '::players' do
10
+ before(:each) do
11
+ described_class.response = json_response
12
+ end
13
+ after :each do
14
+ described_class.response = nil
15
+ end
16
+
17
+ it 'has these 2 keys' do
18
+ expected_keys = %w(76561198012598620 76561198045802942)
19
+ actual = described_class.players.keys
20
+ expect(actual).to match_array expected_keys
21
+ end
22
+ it 'each key points to an instance of BackpackTF::User' do
23
+ actual = described_class.players.values
24
+ expect(actual).to all be_a BackpackTF::User
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::UserListing::Interface do
4
+ it 'has these default attributes' do
5
+ expect(described_class.name).to eq :IGetUserListings
6
+ expect(described_class.version).to eq 2
7
+ expect(described_class.steamid).to eq nil
8
+ end
9
+ describe '::defaults' do
10
+ after(:each) do
11
+ described_class.class_eval { @steamid = nil }
12
+ end
13
+
14
+ it 'can modify its values' do
15
+ options = { steamid: 1 }
16
+ described_class.defaults(options)
17
+ expect(described_class.steamid).to eq 1
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::UserListing::Response do
4
+ let(:json_response) do
5
+ fixture = file_fixture('user_listing.json')
6
+ JSON.parse(fixture)['response']
7
+ end
8
+
9
+ describe '::listings' do
10
+ before(:each) do
11
+ described_class.response = json_response
12
+ end
13
+ after :each do
14
+ described_class.response = nil
15
+ end
16
+
17
+ it 'each entry is an instance of BackpackTF::UserListing' do
18
+ expect(described_class.listings).to all be_a BackpackTF::UserListing
19
+ end
20
+ end
21
+ end
@@ -1,90 +1,62 @@
1
1
  require 'spec_helper'
2
2
 
3
- module BackpackTF
4
- describe UserListing do
5
- let(:bp) { Client.new }
6
-
7
- let(:json_obj) {
8
- fixture = file_fixture('user_listing.json')
9
- fixture = JSON.parse(fixture)['response']
10
- Response.hash_keys_to_sym(fixture)
11
- }
12
-
13
- it 'has these default attributes' do
14
- expect(described_class.interface).to eq :IGetUserListings
15
- end
3
+ describe BackpackTF::UserListing do
4
+ let(:response_attr) do
5
+ fixture = file_fixture('user_listing_individual.json')
6
+ JSON.parse(fixture)
7
+ end
16
8
 
9
+ describe '#initialize' do
17
10
  it 'an instance has these attributes' do
18
- some_json = JSON.parse(file_fixture 'user_listing.json')['response']['listings'][0]
19
- listing = described_class.new(some_json)
20
- expected_item = {:id=>3701558065, :original_id=>3682615727, :defindex=>5042, :level=>5, :quality=>6, :inventory=>2147484348, :quantity=>1, :origin=>2, :attributes=>[{:defindex=>195, :value=>1065353216, :float_value=>1}, {:defindex=>2046, :value=>1065353216, :float_value=>1}]}
11
+ listing = described_class.new(response_attr)
12
+
13
+ expected_item = {
14
+ id: 4224171036,
15
+ original_id: 4114938468,
16
+ defindex: 937,
17
+ level: 85,
18
+ quality: 5,
19
+ inventory: 3221225475,
20
+ quantity: 1,
21
+ origin: 8,
22
+ attributes: [{
23
+ defindex: 134,
24
+ value: 1088421888,
25
+ float_value: 7
26
+ }, {
27
+ defindex: 746,
28
+ value: 1065353216,
29
+ float_value: 1
30
+ }, {
31
+ defindex: 292,
32
+ value: 1115684864,
33
+ float_value: 64
34
+ }, {
35
+ defindex: 388,
36
+ value: 1115684864,
37
+ float_value: 64
38
+ }]
39
+ }
40
+ expected_flag = {
41
+ class: 'pyro',
42
+ slot: 'misc',
43
+ particle: 7,
44
+ craft_material_type: 'hat',
45
+ priceindex: 7,
46
+ sku: '440_Unusual_Wraith Wrap_1_1_7',
47
+ }
48
+
21
49
  expect(listing).to have_attributes(
22
- :id => :'440_3701558065',
23
- :bump => 1431107557,
24
- :created => 1429875049,
25
- :currencies => { 'keys' => 1 },
26
- :item => expected_item,
27
- :details => "or 1,33 key in items (no paints,parts etc.); got more in stock :) add me, send TO or use my 24\/7 http:\/\/dispenser.tf\/id\/76561197978210095",
28
- :meta => {:class => 'multi', :slot => 'tool', :craft_material_type => 'tool'},
29
- :buyout => 1,
50
+ bump: 1453660379,
51
+ intent: 1,
52
+ currencies: { keys: 58 },
53
+ buyout: 1,
54
+ details: false,
55
+ item: expected_item,
56
+ flags: expected_flag,
57
+ created: 1445205322,
58
+ id: '5624154aba8d884610a41c51'
30
59
  )
31
60
  end
32
-
33
- describe '::response' do
34
- before :all do
35
- expect(described_class.response).to be_nil
36
- end
37
-
38
- before :each do
39
- stub_http_response_with('user_listing.json')
40
- opts = { :compress => 1, :steamid => 76561197978210095 }
41
- fetched_listings = bp.fetch(:user_listings, opts)
42
- Response.responses(described_class.to_sym => fetched_listings)
43
- end
44
-
45
- after :all do
46
- Response.responses(:reset => :confirm)
47
- expect(Response.responses).to be_empty
48
- expect(described_class.response).to be_nil
49
- expect(described_class.listings).to be_nil
50
- end
51
-
52
- it 'the keys of the response attribute should have these values' do
53
- expect(described_class.response[:success]).to eq 1
54
- expect(described_class.response[:message]).to eq nil
55
- expect(described_class.response[:current_time]).to eq 1431120247
56
- end
57
- end
58
-
59
- describe '::listings' do
60
- before :all do
61
- expect(described_class.response).to be_nil
62
- expect(described_class.listings).to be_nil
63
- end
64
-
65
- before :each do
66
- stub_http_response_with('user_listing.json')
67
- opts = { :compress => 1, :steamid => 76561197978210095 }
68
- fetched_listings = bp.fetch(:user_listings, opts)
69
- Response.responses(described_class.to_sym => fetched_listings)
70
- end
71
-
72
- after :all do
73
- Response.responses(:reset => :confirm)
74
- expect(Response.responses).to be_empty
75
- described_class.class_eval { @listings = nil }
76
- end
77
-
78
- it 'returns the fixture and sets to @@listings variable' do
79
- expect(described_class.listings).not_to be_nil
80
- end
81
- it 'is an Array object' do
82
- expect(described_class.listings).to be_instance_of Array
83
- end
84
- it 'each entry is an instance of UserListing' do
85
- expect(described_class.listings).to all be_a described_class
86
- end
87
- end
88
-
89
61
  end
90
62
  end
@@ -1,92 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
- module BackpackTF
4
- describe User do
5
- let(:bp) { Client.new }
6
-
7
- let(:json_obj) {
8
- fixture = file_fixture('users.json')
9
- fixture = JSON.parse(fixture)['response']
10
- Response.hash_keys_to_sym(fixture)
11
- }
12
-
13
- it 'has these default attributes' do
14
- expect(described_class.interface).to eq :IGetUsers
15
- end
3
+ describe BackpackTF::User do
4
+ let(:json_response) do
5
+ fixture = file_fixture('users.json')
6
+ JSON.parse(fixture)['response']
7
+ end
16
8
 
9
+ describe '#initialize' do
17
10
  it 'an instance has these attributes' do
18
- some_json = JSON.parse(file_fixture 'users.json')['response']['players']['76561198012598620']
19
- user = described_class.new(some_json)
11
+ attr = json_response['players']['76561198012598620']
12
+ user = described_class.new(attr)
20
13
  expect(user).to have_attributes(
21
- :steamid => '76561198012598620',
22
- :success => 1,
23
- :backpack_value => { '440' => 521.4655, '570' => 0 },
24
- :name => 'Fiskie',
25
- :backpack_tf_reputation => 26,
26
- :backpack_tf_group => true,
27
- :backpack_tf_trust => { 'for' => 3, 'against' => 0 },
28
- :notifications => 0
14
+ steamid: '76561198012598620',
15
+ success: 1,
16
+ backpack_value: { '440' => 521.4655, '570' => 0 },
17
+ name: 'Fiskie',
18
+ backpack_tf_reputation: 26,
19
+ backpack_tf_group: true,
20
+ backpack_tf_trust: { 'for' => 3, 'against' => 0 },
21
+ notifications: 0
29
22
  )
30
23
  end
31
-
32
- describe '::response' do
33
- before :all do
34
- expect(described_class.response).to be_nil
35
- end
36
-
37
- before :each do
38
- stub_http_response_with('users.json')
39
- opts = {:steamids => [76561198012598620,76561198045802942]}
40
- fetched_users = bp.fetch(:users, opts)
41
- bp.update(described_class, fetched_users)
42
- end
43
-
44
- after :all do
45
- Response.responses(:reset => :confirm)
46
- expect(Response.responses).to be_empty
47
- expect(described_class.response).to be_nil
48
- expect(described_class.players).to be_nil
49
- end
50
-
51
- it 'the keys of the response attribute should have these values' do
52
- expect(described_class.response[:success]).to eq 1
53
- expect(described_class.response[:message]).to eq nil
54
- expect(described_class.response[:current_time]).to eq 1431115863
55
- end
56
- end
57
-
58
- describe '::players' do
59
- before :all do
60
- expect(described_class.response).to be_nil
61
- expect(described_class.players).to be_nil
62
- end
63
-
64
- before :each do
65
- stub_http_response_with('users.json')
66
- opts = {:steamids => [76561198012598620,76561198045802942]}
67
- fetched_users = bp.fetch(:users, opts)
68
- bp.update(described_class, fetched_users)
69
- end
70
-
71
- after :all do
72
- Response.responses(:reset => :confirm)
73
- expect(Response.responses).to be_empty
74
- described_class.class_eval { @players = nil }
75
- end
76
-
77
- it 'returns the fixture and sets to @@players variable' do
78
- expect(described_class.players).not_to be_nil
79
- end
80
- it 'is a Hash object' do
81
- expect(described_class.players).to be_instance_of Hash
82
- end
83
- it 'has these 2 keys' do
84
- expect(described_class.players.keys).to match_array ['76561198012598620', '76561198045802942']
85
- end
86
- it 'each key points to an instance of SpecialItem' do
87
- expect(described_class.players.values).to all be_a described_class
88
- end
89
- end
90
-
91
24
  end
92
25
  end
@@ -0,0 +1,6 @@
1
+ {
2
+ "currency": "metal",
3
+ "value": 0.05,
4
+ "last_update": 1336410088,
5
+ "difference": 0
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "currency": "keys",
3
+ "value": 18,
4
+ "last_update": 1418795322,
5
+ "difference": 280,
6
+ "value_high": 22
7
+ }
@@ -1 +1 @@
1
- {"Kritzkrieg":{"defindex":[35],"prices":{"11":{"Tradable":{"Craftable":[{"currency":"keys","value":18,"last_update":1430665867,"difference":-18.495}]}},"14":{"Tradable":{"Craftable":[{"currency":"keys","value":9,"last_update":1416841372,"difference":11.385}]}},"3":{"Tradable":{"Craftable":[{"currency":"metal","value":0.66,"last_update":1426439779,"difference":0.33}]}},"6":{"Tradable":{"Craftable":[{"currency":"metal","value":0.05,"last_update":1336410088,"difference":0}],"Non-Craftable":[{"currency":"metal","value":0.05,"last_update":1362791812,"difference":0.03}]}}}}}
1
+ {"Kritzkrieg":{"defindex":[35],"prices":{"11":{"Tradable":{"Craftable":{"0":{"currency":"keys","value":15,"last_update":1452807352,"difference":17.495}}}},"14":{"Tradable":{"Craftable":{"0":{"currency":"keys","value":12,"last_update":1436107703,"difference":57.165}}}},"3":{"Tradable":{"Craftable":{"0":{"currency":"metal","value":0.55,"last_update":1450942755,"difference":0.11,"value_high":0.77}}}},"6":{"Tradable":{"Craftable":{"0":{"currency":"metal","value":0.05,"last_update":1336410088,"difference":0}},"Non-Craftable":{"0":{"currency":"metal","value":0.05,"last_update":1439069757,"difference":-0.06}}}}}}}