giant_bomb_api 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +6 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/Gemfile +2 -0
  8. data/Gemfile.lock +81 -0
  9. data/LICENSE +22 -0
  10. data/README.md +155 -0
  11. data/Rakefile +7 -0
  12. data/circle.yml +6 -0
  13. data/giant_bomb_api.gemspec +31 -0
  14. data/lib/giant_bomb_api.rb +38 -0
  15. data/lib/giant_bomb_api/client.rb +54 -0
  16. data/lib/giant_bomb_api/collection_resource.rb +40 -0
  17. data/lib/giant_bomb_api/exception.rb +5 -0
  18. data/lib/giant_bomb_api/exception/api_error.rb +14 -0
  19. data/lib/giant_bomb_api/request.rb +10 -0
  20. data/lib/giant_bomb_api/request/collection.rb +36 -0
  21. data/lib/giant_bomb_api/request/detail.rb +9 -0
  22. data/lib/giant_bomb_api/request/search.rb +18 -0
  23. data/lib/giant_bomb_api/resource.rb +34 -0
  24. data/lib/giant_bomb_api/resource/accessory.rb +10 -0
  25. data/lib/giant_bomb_api/resource/character.rb +24 -0
  26. data/lib/giant_bomb_api/resource/chat.rb +11 -0
  27. data/lib/giant_bomb_api/resource/company.rb +32 -0
  28. data/lib/giant_bomb_api/resource/concept.rb +21 -0
  29. data/lib/giant_bomb_api/resource/factory.rb +36 -0
  30. data/lib/giant_bomb_api/resource/franchise.rb +17 -0
  31. data/lib/giant_bomb_api/resource/game.rb +40 -0
  32. data/lib/giant_bomb_api/resource/game_rating.rb +8 -0
  33. data/lib/giant_bomb_api/resource/genre.rb +10 -0
  34. data/lib/giant_bomb_api/resource/image.rb +12 -0
  35. data/lib/giant_bomb_api/resource/location.rb +12 -0
  36. data/lib/giant_bomb_api/resource/object.rb +20 -0
  37. data/lib/giant_bomb_api/resource/person.rb +24 -0
  38. data/lib/giant_bomb_api/resource/platform.rb +16 -0
  39. data/lib/giant_bomb_api/resource/promo.rb +11 -0
  40. data/lib/giant_bomb_api/resource/rating_board.rb +11 -0
  41. data/lib/giant_bomb_api/resource/region.rb +11 -0
  42. data/lib/giant_bomb_api/resource/release.rb +24 -0
  43. data/lib/giant_bomb_api/resource/review.rb +15 -0
  44. data/lib/giant_bomb_api/resource/theme.rb +7 -0
  45. data/lib/giant_bomb_api/resource/user_review.rb +11 -0
  46. data/lib/giant_bomb_api/resource/video.rb +17 -0
  47. data/lib/giant_bomb_api/resource/video_type.rb +8 -0
  48. data/lib/giant_bomb_api/resource_value_setter.rb +29 -0
  49. data/lib/giant_bomb_api/response.rb +17 -0
  50. data/spec/fixtures/detail-response.json +740 -0
  51. data/spec/fixtures/search-response.json +59 -0
  52. data/spec/lib/collection_resource_spec.rb +76 -0
  53. data/spec/lib/giant_bomb_api_spec.rb +56 -0
  54. data/spec/lib/request/collection_spec.rb +32 -0
  55. data/spec/lib/request/search_spec.rb +38 -0
  56. data/spec/lib/resource/factory_spec.rb +35 -0
  57. data/spec/lib/resource/game_spec.rb +28 -0
  58. data/spec/lib/resource_spec.rb +37 -0
  59. data/spec/lib/response_spec.rb +102 -0
  60. data/spec/spec_helper.rb +15 -0
  61. metadata +241 -0
@@ -0,0 +1,5 @@
1
+ module GiantBombApi
2
+ class Exception < StandardError
3
+
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ module GiantBombApi
2
+ class Exception::ApiError < GiantBombApi::Exception
3
+
4
+ def initialize(status_code, message)
5
+ @status_code = status_code
6
+ @message = message
7
+ end
8
+
9
+ def message
10
+ "#Status: {status_code} - #{message}"
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module GiantBombApi
2
+ class Request
3
+ attr_accessor :params, :end_point
4
+
5
+ def initialize(end_point, params)
6
+ @params = params
7
+ @end_point = end_point
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,36 @@
1
+ module GiantBombApi
2
+ class Request::Collection < GiantBombApi::Request
3
+
4
+ def initialize(resource, filter: {}, sort: {}, limit: 100, offset: 0)
5
+ @resource = resource
6
+ @filter = filter
7
+ @sort = sort
8
+
9
+ params = {}
10
+ params[:filter] = filter_params if filter_params.present?
11
+ params[:sort] = sort_params if sort_params.present?
12
+ params[:limit] = limit if limit.present?
13
+ params[:offset] = offset if offset.present?
14
+
15
+ super end_point, params
16
+ end
17
+
18
+ def filter_params
19
+ params_join @filter
20
+ end
21
+
22
+ def sort_params
23
+ params_join @sort
24
+ end
25
+
26
+ def end_point
27
+ @resource.collection_resource_name
28
+ end
29
+
30
+ private
31
+
32
+ def params_join(params)
33
+ params.map { |key,value| "#{key}:#{value}" }.join(",")
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ module GiantBombApi
2
+ class Request::Detail < GiantBombApi::Request
3
+
4
+ def initialize(resource_name, id, params = {})
5
+ super "#{resource_name}/#{id}", params
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module GiantBombApi
2
+ class Request::Search < GiantBombApi::Request
3
+
4
+ def initialize(query, resources: [GiantBombApi::Resource::Game], limit: 100, page: 1)
5
+ params = {
6
+ query: query,
7
+ resources: resources.map { |res| res.resource_name }.join(','),
8
+ limit: limit,
9
+ page: page
10
+ }
11
+ super end_point, params
12
+ end
13
+
14
+ def end_point
15
+ '/search'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ module GiantBombApi
2
+ module Resource
3
+
4
+ def self.extended(base)
5
+ base.instance_variable_set("@resource_attributes", {})
6
+ base.include ResourceValueSetter
7
+
8
+ base.class_eval do
9
+ resource_attribute :id, :api_detail_url, :date_added, :date_last_updated
10
+ end
11
+ end
12
+
13
+ def resource_name(resource_name = nil)
14
+ if resource_name.present?
15
+ self.instance_variable_set("@resource_name", resource_name)
16
+ end
17
+ self.instance_variable_get("@resource_name") || self.name.split('::').last.underscore
18
+ end
19
+
20
+ def find(id, params = {})
21
+ GiantBombApi.client.send_request(Request::Detail.new(resource_name, id, params))
22
+ end
23
+
24
+ def resource_attribute(*attributes, resource_name: nil)
25
+ attributes.each do |attribute_name|
26
+ instance_variable_get("@resource_attributes")[attribute_name] = resource_name
27
+
28
+ class_eval do
29
+ attr_accessor attribute_name
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ module GiantBombApi
2
+ class Resource::Accessory
3
+ extend GiantBombApi::CollectionResource
4
+ resource_attribute :deck
5
+ resource_attribute :description
6
+ resource_attribute :image
7
+ resource_attribute :name
8
+ resource_attribute :site_detail_url
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ module GiantBombApi
2
+ class Resource::Character
3
+ extend GiantBombApi::CollectionResource
4
+ resource_attribute :aliases
5
+ resource_attribute :birthday
6
+ resource_attribute :concepts
7
+ resource_attribute :deck
8
+ resource_attribute :description
9
+ resource_attribute :enemies
10
+ resource_attribute :first_appeared_in_game, resource_name: :game
11
+ resource_attribute :franchises
12
+ resource_attribute :friends
13
+ resource_attribute :games
14
+ resource_attribute :gender
15
+ resource_attribute :image
16
+ resource_attribute :last_name
17
+ resource_attribute :locations
18
+ resource_attribute :name
19
+ resource_attribute :objects
20
+ resource_attribute :people
21
+ resource_attribute :real_name
22
+ resource_attribute :site_detail_url
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module GiantBombApi
2
+ class Resource::Chat
3
+ extend GiantBombApi::CollectionResource
4
+ resource_name :channel_name
5
+ resource_name :deck
6
+ resource_name :image
7
+ resource_name :password
8
+ resource_name :site_detail_url
9
+ resource_name :title
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ module GiantBombApi
2
+ class Resource::Company
3
+ extend GiantBombApi::CollectionResource
4
+ resource_attribute :abbreviation
5
+ resource_attribute :aliases
6
+ resource_attribute :characters
7
+ resource_attribute :concepts
8
+ resource_attribute :date_last_updated
9
+ resource_attribute :deck
10
+ resource_attribute :description
11
+ resource_attribute :developed_games, resource_name: :game
12
+ resource_attribute :developer_releases, resource_name: :release
13
+ resource_attribute :distributor_releases, resource_name: :release
14
+ resource_attribute :image
15
+ resource_attribute :location_address
16
+ resource_attribute :location_city
17
+ resource_attribute :location_country
18
+ resource_attribute :location_address
19
+ resource_attribute :location_city
20
+ resource_attribute :location_country
21
+ resource_attribute :location_state
22
+ resource_attribute :locations
23
+ resource_attribute :name
24
+ resource_attribute :objects
25
+ resource_attribute :people
26
+ resource_attribute :phone
27
+ resource_attribute :published_games, resource_name: :game
28
+ resource_attribute :publisher_releases, resource_name: :release
29
+ resource_attribute :site_detail_url
30
+ resource_attribute :website
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ module GiantBombApi
2
+ class Resource::Concept
3
+ extend GiantBombApi::CollectionResource
4
+ resource_attribute :aliases
5
+ resource_attribute :characters
6
+ resource_attribute :concepts
7
+ resource_attribute :deck
8
+ resource_attribute :description
9
+ resource_attribute :first_appeared_in_franchise
10
+ resource_attribute :first_appeared_in_game, resource_name: :game
11
+ resource_attribute :franchises
12
+ resource_attribute :games
13
+ resource_attribute :image
14
+ resource_attribute :locations
15
+ resource_attribute :name
16
+ resource_attribute :objects
17
+ resource_attribute :people
18
+ resource_attribute :related_concepts, resource_name: :concept
19
+ resource_attribute :site_detail_url
20
+ end
21
+ end
@@ -0,0 +1,36 @@
1
+ module GiantBombApi
2
+ class Resource::Factory
3
+
4
+ def self.init_resource_from(json, attribute_name: nil, resource_name: nil)
5
+ resource_name ||= discover_resource_name(json["api_detail_url"])
6
+ resource_name ||= attribute_name if resource_exists?(attribute_name)
7
+ resource_name ||= attribute_name.to_s.singularize if resource_exists?(attribute_name.to_s.singularize)
8
+ return if resource_name.nil?
9
+
10
+ init_object(resource_name, json)
11
+ end
12
+
13
+ def self.init_object(resource_name, json)
14
+ if resource_exists? resource_name
15
+ constant_for(resource_name).constantize.new(json)
16
+ end
17
+ end
18
+
19
+ def self.discover_resource_name(string)
20
+ return unless string
21
+ match_data = string.match("/api/(?<resource_name>[a-z_]*)/")
22
+ return if match_data.nil?
23
+ return match_data["resource_name"]
24
+ end
25
+
26
+ def self.resource_exists?(resource_name)
27
+ return false unless resource_name.present?
28
+ Object.const_defined? constant_for(resource_name)
29
+ end
30
+
31
+ def self.constant_for(resource_name)
32
+ "GiantBombApi::Resource::#{resource_name.to_s.classify}"
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ module GiantBombApi
2
+ class Resource::Franchise
3
+ extend GiantBombApi::CollectionResource
4
+ resource_attribute :aliases
5
+ resource_attribute :characters
6
+ resource_attribute :concepts
7
+ resource_attribute :deck
8
+ resource_attribute :description
9
+ resource_attribute :games
10
+ resource_attribute :image
11
+ resource_attribute :locations
12
+ resource_attribute :name
13
+ resource_attribute :objects
14
+ resource_attribute :people
15
+ resource_attribute :site_detail_url
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ module GiantBombApi
2
+ class Resource::Game
3
+ extend GiantBombApi::CollectionResource
4
+ resource_attribute :aliases
5
+ resource_attribute :characters
6
+ resource_attribute :concepts
7
+ resource_attribute :deck
8
+ resource_attribute :description
9
+ resource_attribute :developers, resource_name: :company
10
+ resource_attribute :expected_release_day
11
+ resource_attribute :expected_release_month
12
+ resource_attribute :expected_release_quarter
13
+ resource_attribute :expected_release_year
14
+ resource_attribute :first_appearance_characters, resource_name: :character
15
+ resource_attribute :first_appearance_concepts, resource_name: :concept
16
+ resource_attribute :first_appearance_locations, resource_name: :location
17
+ resource_attribute :first_appearance_objects
18
+ resource_attribute :first_appearance_people
19
+ resource_attribute :franchises
20
+ resource_attribute :genres
21
+ resource_attribute :image
22
+ resource_attribute :images
23
+ resource_attribute :killed_characters, resource_name: :character
24
+ resource_attribute :locations
25
+ resource_attribute :name
26
+ resource_attribute :number_of_user_reviews
27
+ resource_attribute :objects
28
+ resource_attribute :original_game_rating
29
+ resource_attribute :original_release_date
30
+ resource_attribute :people
31
+ resource_attribute :platforms
32
+ resource_attribute :publishers, resource_name: :company
33
+ resource_attribute :releases
34
+ resource_attribute :reviews
35
+ resource_attribute :similar_games, resource_name: :game
36
+ resource_attribute :site_detail_url
37
+ resource_attribute :themes
38
+ resource_attribute :videos
39
+ end
40
+ end
@@ -0,0 +1,8 @@
1
+ module GiantBombApi
2
+ class Resource::GameRating
3
+ extend GiantBombApi::CollectionResource
4
+ resource_attribute :image
5
+ resource_attribute :name
6
+ resource_attribute :rating_board
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module GiantBombApi
2
+ class Resource::Genre
3
+ extend GiantBombApi::CollectionResource
4
+ resource_attribute :deck
5
+ resource_attribute :description
6
+ resource_attribute :image
7
+ resource_attribute :name
8
+ resource_attribute :site_detail_url
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module GiantBombApi
2
+ class Resource::Image
3
+ extend GiantBombApi::Resource
4
+ resource_attribute :icon_url
5
+ resource_attribute :medium_url
6
+ resource_attribute :screen_url
7
+ resource_attribute :small_url
8
+ resource_attribute :super_url
9
+ resource_attribute :thumb_url
10
+ resource_attribute :tiny_url
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module GiantBombApi
2
+ class Resource::Location
3
+ extend GiantBombApi::CollectionResource
4
+ resource_attribute :aliases
5
+ resource_attribute :deck
6
+ resource_attribute :description
7
+ resource_attribute :first_appeared_in_game, resource_name: :game
8
+ resource_attribute :image
9
+ resource_attribute :name
10
+ resource_attribute :site_detail_url
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module GiantBombApi
2
+ class Resource::Object
3
+ extend GiantBombApi::CollectionResource
4
+ resource_attribute :aliases
5
+ resource_attribute :characters
6
+ resource_attribute :companies
7
+ resource_attribute :concepts
8
+ resource_attribute :deck
9
+ resource_attribute :description
10
+ resource_attribute :first_appeared_in_game, resource_name: :game
11
+ resource_attribute :franchises
12
+ resource_attribute :games
13
+ resource_attribute :image
14
+ resource_attribute :locations
15
+ resource_attribute :name
16
+ resource_attribute :objects
17
+ resource_attribute :people
18
+ resource_attribute :site_detail_url
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ module GiantBombApi
2
+ class Resource::Person
3
+ extend GiantBombApi::CollectionResource
4
+ resource_attribute :aliases
5
+ resource_attribute :birth_date
6
+ resource_attribute :characters
7
+ resource_attribute :concepts
8
+ resource_attribute :country
9
+ resource_attribute :death_date
10
+ resource_attribute :deck
11
+ resource_attribute :description
12
+ resource_attribute :first_credited_game, resource_name: :game
13
+ resource_attribute :franchises
14
+ resource_attribute :games
15
+ resource_attribute :gender
16
+ resource_attribute :hometown
17
+ resource_attribute :image
18
+ resource_attribute :locations
19
+ resource_attribute :name
20
+ resource_attribute :objects
21
+ resource_attribute :people
22
+ resource_attribute :site_detail_url
23
+ end
24
+ end