nexus_mods 0.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/lib/nexus_mods/api/api_limits.rb +64 -0
  4. data/lib/nexus_mods/api/category.rb +54 -0
  5. data/lib/nexus_mods/api/game.rb +106 -0
  6. data/lib/nexus_mods/api/mod.rb +141 -0
  7. data/lib/nexus_mods/api/mod_file.rb +116 -0
  8. data/lib/nexus_mods/api/user.rb +55 -0
  9. data/lib/nexus_mods/api_client.rb +182 -0
  10. data/lib/nexus_mods/cacheable_api.rb +52 -0
  11. data/lib/nexus_mods/cacheable_with_expiry.rb +70 -0
  12. data/lib/nexus_mods/core_extensions/cacheable/cache_adapters/persistent_json_adapter.rb +62 -0
  13. data/lib/nexus_mods/core_extensions/cacheable/method_generator.rb +62 -0
  14. data/lib/nexus_mods/file_cache.rb +71 -0
  15. data/lib/nexus_mods/version.rb +1 -1
  16. data/lib/nexus_mods.rb +32 -86
  17. data/spec/nexus_mods_test/factories/games.rb +135 -0
  18. data/spec/nexus_mods_test/factories/mod_files.rb +113 -0
  19. data/spec/nexus_mods_test/factories/mods.rb +144 -0
  20. data/spec/nexus_mods_test/helpers.rb +39 -14
  21. data/spec/nexus_mods_test/scenarios/nexus_mods/{api_limits_spec.rb → api/api_limits_spec.rb} +10 -3
  22. data/spec/nexus_mods_test/scenarios/nexus_mods/api/game_spec.rb +93 -0
  23. data/spec/nexus_mods_test/scenarios/nexus_mods/api/mod_file_spec.rb +73 -0
  24. data/spec/nexus_mods_test/scenarios/nexus_mods/api/mod_spec.rb +62 -0
  25. data/spec/nexus_mods_test/scenarios/nexus_mods_caching_spec.rb +88 -0
  26. metadata +37 -13
  27. data/lib/nexus_mods/api_limits.rb +0 -44
  28. data/lib/nexus_mods/category.rb +0 -37
  29. data/lib/nexus_mods/game.rb +0 -78
  30. data/lib/nexus_mods/mod.rb +0 -106
  31. data/lib/nexus_mods/mod_file.rb +0 -86
  32. data/lib/nexus_mods/user.rb +0 -37
  33. data/spec/nexus_mods_test/scenarios/nexus_mods/game_spec.rb +0 -180
  34. data/spec/nexus_mods_test/scenarios/nexus_mods/mod_file_spec.rb +0 -140
  35. data/spec/nexus_mods_test/scenarios/nexus_mods/mod_spec.rb +0 -185
@@ -1,185 +0,0 @@
1
- describe NexusMods::Mod do
2
-
3
- context 'when testing mods' do
4
-
5
- # Example of JSON object returned by the API for a mod information, having all possible fields
6
- let(:json_complete_mod) do
7
- {
8
- 'name' => 'ApachiiSkyHair SSE',
9
- 'summary' => 'New Female and Male Hairstyles for Humans, Elves and Orcs. Converted hair from Sims2 and Sims3.<br />Standalone version.',
10
- 'description' => 'Mod description',
11
- 'picture_url' => 'https://staticdelivery.nexusmods.com/mods/1704/images/10168-1-1392817986.jpg',
12
- 'mod_downloads' => 13_634_545,
13
- 'mod_unique_downloads' => 4_052_221,
14
- 'uid' => 7_318_624_272_650,
15
- 'mod_id' => 2014,
16
- 'game_id' => 1704,
17
- 'allow_rating' => true,
18
- 'domain_name' => 'skyrimspecialedition',
19
- 'category_id' => 26,
20
- 'version' => '1.6.Full',
21
- 'endorsement_count' => 298_845,
22
- 'created_timestamp' => 1_477_972_056,
23
- 'created_time' => '2016-11-01T03:47:36.000+00:00',
24
- 'updated_timestamp' => 1_507_398_546,
25
- 'updated_time' => '2017-10-07T17:49:06.000+00:00',
26
- 'author' => 'Apachii',
27
- 'uploaded_by' => 'apachii',
28
- 'uploaded_users_profile_url' => 'http://www.nexusmods.com/games/users/283148',
29
- 'contains_adult_content' => false,
30
- 'status' => 'published',
31
- 'available' => true,
32
- 'user' => {
33
- 'member_id' => 283_148,
34
- 'member_group_id' => 27,
35
- 'name' => 'apachii'
36
- },
37
- 'endorsement' => {
38
- 'endorse_status' => 'Undecided',
39
- 'timestamp' => nil,
40
- 'version' => nil
41
- }
42
- }
43
- end
44
-
45
- # Example of JSON object returned by the API for a mod information, having minimum fields
46
- let(:json_partial_mod) do
47
- {
48
- 'mod_downloads' => 13_634_545,
49
- 'mod_unique_downloads' => 4_052_221,
50
- 'uid' => 7_318_624_272_650,
51
- 'mod_id' => 2014,
52
- 'game_id' => 1704,
53
- 'allow_rating' => true,
54
- 'domain_name' => 'skyrimspecialedition',
55
- 'category_id' => 26,
56
- 'version' => '1.6.Full',
57
- 'endorsement_count' => 298_845,
58
- 'created_timestamp' => 1_477_972_056,
59
- 'created_time' => '2016-11-01T03:47:36.000+00:00',
60
- 'updated_timestamp' => 1_507_398_546,
61
- 'updated_time' => '2017-10-07T17:49:06.000+00:00',
62
- 'author' => 'Apachii',
63
- 'uploaded_by' => 'apachii',
64
- 'uploaded_users_profile_url' => 'http://www.nexusmods.com/games/users/283148',
65
- 'contains_adult_content' => false,
66
- 'status' => 'published',
67
- 'available' => true,
68
- 'user' => {
69
- 'member_id' => 283_148,
70
- 'member_group_id' => 27,
71
- 'name' => 'apachii'
72
- }
73
- }
74
- end
75
-
76
- # Expect a mod to be the example complete one
77
- #
78
- # Parameters::
79
- # * *mod* (NexusMods::Mod): Mod to validate
80
- def expect_mod_to_be_complete(mod)
81
- expect(mod.name).to eq 'ApachiiSkyHair SSE'
82
- expect(mod.summary).to eq 'New Female and Male Hairstyles for Humans, Elves and Orcs. Converted hair from Sims2 and Sims3.<br />Standalone version.'
83
- expect(mod.description).to eq 'Mod description'
84
- expect(mod.picture_url).to eq 'https://staticdelivery.nexusmods.com/mods/1704/images/10168-1-1392817986.jpg'
85
- expect(mod.downloads_count).to eq 13_634_545
86
- expect(mod.unique_downloads_count).to eq 4_052_221
87
- expect(mod.uid).to eq 7_318_624_272_650
88
- expect(mod.mod_id).to eq 2014
89
- expect(mod.game_id).to eq 1704
90
- expect(mod.allow_rating).to be true
91
- expect(mod.domain_name).to eq 'skyrimspecialedition'
92
- expect(mod.category_id).to eq 26
93
- expect(mod.version).to eq '1.6.Full'
94
- expect(mod.endorsements_count).to eq 298_845
95
- expect(mod.created_time).to eq Time.parse('2016-11-01T03:47:36.000+00:00')
96
- expect(mod.updated_time).to eq Time.parse('2017-10-07T17:49:06.000+00:00')
97
- expect(mod.author).to eq 'Apachii'
98
- expect(mod.contains_adult_content).to be false
99
- expect(mod.status).to eq 'published'
100
- expect(mod.available).to be true
101
- expect(mod.uploader.member_id).to eq 283_148
102
- expect(mod.uploader.member_group_id).to eq 27
103
- expect(mod.uploader.name).to eq 'apachii'
104
- expect(mod.uploader.profile_url).to eq 'http://www.nexusmods.com/games/users/283148'
105
- end
106
-
107
- # Expect a mod to be the example partial one
108
- #
109
- # Parameters::
110
- # * *mod* (NexusMods::Mod): Mod to validate
111
- def expect_mod_to_be_partial(mod)
112
- expect(mod.name).to be_nil
113
- expect(mod.summary).to be_nil
114
- expect(mod.description).to be_nil
115
- expect(mod.picture_url).to be_nil
116
- expect(mod.downloads_count).to eq 13_634_545
117
- expect(mod.unique_downloads_count).to eq 4_052_221
118
- expect(mod.uid).to eq 7_318_624_272_650
119
- expect(mod.mod_id).to eq 2014
120
- expect(mod.game_id).to eq 1704
121
- expect(mod.allow_rating).to be true
122
- expect(mod.domain_name).to eq 'skyrimspecialedition'
123
- expect(mod.category_id).to eq 26
124
- expect(mod.version).to eq '1.6.Full'
125
- expect(mod.endorsements_count).to eq 298_845
126
- expect(mod.created_time).to eq Time.parse('2016-11-01T03:47:36.000+00:00')
127
- expect(mod.updated_time).to eq Time.parse('2017-10-07T17:49:06.000+00:00')
128
- expect(mod.author).to eq 'Apachii'
129
- expect(mod.contains_adult_content).to be false
130
- expect(mod.status).to eq 'published'
131
- expect(mod.available).to be true
132
- expect(mod.uploader.member_id).to eq 283_148
133
- expect(mod.uploader.member_group_id).to eq 27
134
- expect(mod.uploader.name).to eq 'apachii'
135
- expect(mod.uploader.profile_url).to eq 'http://www.nexusmods.com/games/users/283148'
136
- end
137
-
138
- it 'returns a mod complete information' do
139
- expect_validate_user
140
- expect_http_call_to(
141
- path: '/v1/games/skyrimspecialedition/mods/2014.json',
142
- json: json_complete_mod
143
- )
144
- expect_mod_to_be_complete(nexus_mods.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014))
145
- end
146
-
147
- it 'returns a mod partial information' do
148
- expect_validate_user
149
- expect_http_call_to(
150
- path: '/v1/games/skyrimspecialedition/mods/2014.json',
151
- json: json_partial_mod
152
- )
153
- expect_mod_to_be_partial(nexus_mods.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014))
154
- end
155
-
156
- it 'returns the default mod information' do
157
- expect_validate_user
158
- expect_http_call_to(
159
- path: '/v1/games/skyrimspecialedition/mods/2014.json',
160
- json: json_complete_mod
161
- )
162
- expect_mod_to_be_complete(nexus_mods(mod_id: 2014).mod(game_domain_name: 'skyrimspecialedition'))
163
- end
164
-
165
- it 'returns mod information for the default game' do
166
- expect_validate_user
167
- expect_http_call_to(
168
- path: '/v1/games/skyrimspecialedition/mods/2014.json',
169
- json: json_complete_mod
170
- )
171
- expect_mod_to_be_complete(nexus_mods(game_domain_name: 'skyrimspecialedition').mod(mod_id: 2014))
172
- end
173
-
174
- it 'returns mod information for the default game and mod' do
175
- expect_validate_user
176
- expect_http_call_to(
177
- path: '/v1/games/skyrimspecialedition/mods/2014.json',
178
- json: json_complete_mod
179
- )
180
- expect_mod_to_be_complete(nexus_mods(game_domain_name: 'skyrimspecialedition', mod_id: 2014).mod)
181
- end
182
-
183
- end
184
-
185
- end