igdb_client 0.5.0 → 4.0.0

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
  SHA256:
3
- metadata.gz: a70dde7eec9c2dcd49f0d78d45e276da1d82d7b92b75f70de72a8ba15c924fde
4
- data.tar.gz: f6b0fca3ff708727484dfe3e681d623a8bce7ee552e791c0b1e8b5e822898b01
3
+ metadata.gz: 2b96444eb50a7d47b3e97781be4cf0bfd1b4bf84ca4f66f39a3ce0a812ec83e9
4
+ data.tar.gz: 731a0f96b6cec5c4751ea3b730d7f54aa8b330bcf87b5718d21885ff231f16b8
5
5
  SHA512:
6
- metadata.gz: ab20081e602219067565591de03b7094161f136bcc3b41c6621430eb27e08a7ae3881b19ebfe1c24447c228103cbb9600f55583ba4d2a32888c0dfb23e0ef2d8
7
- data.tar.gz: 2be9be28b1fdac117d86417d5e7a13bd43431b08185317bd0987cfb2bf1965fdea81bf93328c94eda6908681a2116c19c596dd945812bf1f364a05cb7efb206a
6
+ metadata.gz: f023837f9a1ab3a836630a0e6649f69c8ef2f527fb26b59792d901e6755ca2f079578177fccba527dcd60bf854283e8fa5b16c5579e48e31ed9e7595cc1141eb
7
+ data.tar.gz: 43e088c41f1cc7b361db546cf107d8a68e8d6f246b696685c467b4d6ddfdfc0210981e949725ada7705e8d00935c036c5f4b050db48200188e9856734bb707b8
data/README.md CHANGED
@@ -1,56 +1,43 @@
1
1
  # igdb_client
2
- Ruby client interface for IGDB API
2
+ Ruby client interface for IGDB API. Supports API v4.
3
3
 
4
- ## Usage
5
- The client can be used in one of two ways. Either as an instance or a class.
6
- They work pretty much in the same manner.
4
+ ## Installation
5
+ ```ruby
6
+ $ gem install igdb_client
7
+ ```
7
8
 
8
- The structure of queries and results matches the [api documentaion.](https://igdb.github.io/api/)
9
+ ## Usage
10
+ The structure of queries and results matches the [api documentaion.](https://api-docs.igdb.com/)
11
+ You will need client id and a valid token to access the API. The above link explains how to
12
+ acquire them.
9
13
 
10
14
  ##### Instance
11
15
  ```ruby
12
- # initialize with api_key
13
- client = IGDB::Client.new "api_key"
14
-
15
- # methods match IGDB api endpoints, pass an optional hash as query params
16
- client.games 1942, {fields: "name"}
17
-
18
- # pass multiple ids in an array
19
- client.games [1942,3344], {fields: "name,release_dates,esrb.synopsis,rating"}
20
-
21
- # to run a text search on a resource, put search_ before resource name
22
- client.search_games "ibb and obb"
16
+ require 'igdb_client'
23
17
 
24
- # to count number of resources matched, put count_ before resource name
25
- client.count_games {"filter[rating][gt]" => 75}
18
+ # initialize with client id and token
19
+ client = IGDB::Client.new("client_id","token")
26
20
 
27
- # Access retrieved data by using methods matching fields of data
28
- results = client.platform 2
29
- results[0].name
30
- results[0].summary
31
- ```
21
+ # Endpoint can optionally be provided to change from defaults of 'games'
22
+ other_client = IGDB::Client.new("client_id","token", 'characters')
32
23
 
24
+ # Endpoint/token/client_id can be changed on a client
25
+ other_client.endpoint = 'games'
33
26
 
27
+ # Use the get method to fetch given the API params
28
+ client.get {fields: "name", limit: 10}
34
29
 
35
- ##### Class Methods
36
- ```ruby
37
- # initialize with api_key
38
- IGDB::API.api_key = "api_key"
39
-
40
- # methods match IGDB api endpoints, pass an optional hash as query params
41
- IGDB::API.games 1942, {fields: "name"}
42
-
43
- # pass multiple ids in an array
44
- IGDB::API.games [1942,3344], {fields: "name,release_dates,esrb.synopsis,rating"}
30
+ # Use search method to search
31
+ client.search("ibb and obb", {fields: "name,release_dates,esrb.synopsis,rating"})
45
32
 
46
- # to run a text search on a resource, put search_ before resource name
47
- IGDB::API.search_games "ibb and obb"
33
+ # Use id if you want to match by id
34
+ client.id 1942
48
35
 
49
- # to count number of resources matched, put count_ before resource name
50
- IGDB::API.count_games {"filter[rating][gt]" => 75}
36
+ # You can run methods on alternate endpoints by using endpoint as method
37
+ client.character.id 14390
51
38
 
52
39
  # Access retrieved data by using methods matching fields of data
53
- results = IGDB::API.platform 2
40
+ results = client.platform.id 2
54
41
  results[0].name
55
42
  results[0].summary
56
43
  ```
data/lib/igdb_client.rb CHANGED
@@ -1,2 +1,45 @@
1
- require 'igdb/api'
2
- require 'igdb/client'
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'ostruct'
4
+
5
+ module IGDB
6
+ class Client
7
+ URL = "https://api.igdb.com/v4/"
8
+ HEADER = {"Accept" => "application/json"}
9
+
10
+ attr_accessor :client_id, :token, :endpoint
11
+
12
+ def initialize(client_id, token, endpoint = 'games')
13
+ @client_id = client_id
14
+ @token = token
15
+ @endpoint = endpoint
16
+ end
17
+
18
+ def get(params = {fields: '*'})
19
+ uri = URI.parse(URL+@endpoint)
20
+ data = params.map do |k,v|
21
+ "#{k.to_s} #{v};"
22
+ end.join('')
23
+ response = Net::HTTP.post(uri,
24
+ data,
25
+ HEADER.merge({'Client-ID' => self.client_id,
26
+ 'Authorization' => "Bearer " + self.token}))
27
+ response.value
28
+ JSON.parse(response.body, object_class: OpenStruct)
29
+ end
30
+
31
+ def search(title, params = {fields: '*'})
32
+ params[:search] = '"' + title + '"'
33
+ get params
34
+ end
35
+
36
+ def id(id, params = {fields: '*'})
37
+ params[:where] = "id = #{id}"
38
+ get params
39
+ end
40
+
41
+ def method_missing(m, *args, &block)
42
+ self.class.new(@client_id, @token, m.to_s)
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: igdb_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdulla Bubshait
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-16 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Client for the Internet Game Database
14
14
  email:
@@ -18,15 +18,12 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
- - lib/igdb/api.rb
22
- - lib/igdb/client.rb
23
- - lib/igdb/connection.rb
24
21
  - lib/igdb_client.rb
25
22
  homepage: https://github.com/darkstego/igdb_client
26
23
  licenses:
27
24
  - MIT
28
25
  metadata: {}
29
- post_install_message:
26
+ post_install_message:
30
27
  rdoc_options: []
31
28
  require_paths:
32
29
  - lib
@@ -41,9 +38,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
38
  - !ruby/object:Gem::Version
42
39
  version: '0'
43
40
  requirements: []
44
- rubyforge_project:
45
- rubygems_version: 2.7.5
46
- signing_key:
41
+ rubygems_version: 3.2.29
42
+ signing_key:
47
43
  specification_version: 4
48
- summary: Ruby IGDB API.
44
+ summary: Ruby IGDB API Client
49
45
  test_files: []
data/lib/igdb/api.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'igdb/connection'
2
-
3
- module IGDB
4
- class API
5
- extend IGDB::Connection
6
-
7
- class << self
8
- attr_accessor :api_key
9
- end
10
- end
11
- end
data/lib/igdb/client.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'igdb/connection'
2
-
3
- module IGDB
4
- class Client
5
- include IGDB::Connection
6
-
7
- attr_accessor :api_key
8
-
9
- def initialize(api_key)
10
- @api_key = api_key
11
- end
12
-
13
- end
14
- end
@@ -1,49 +0,0 @@
1
- require 'net/http'
2
- require 'json'
3
- require 'ostruct'
4
-
5
- module IGDB
6
- module Connection
7
- URL = "https://api-endpoint.igdb.com/"
8
- HEADER = {"Accept" => "application/json"}
9
- HEADER_API_KEY_PARAM = "user-key"
10
-
11
- def get path, ids=nil, params={}
12
- uri = URI.parse(URL)
13
- http = Net::HTTP.new(uri.host, uri.port)
14
- http.use_ssl = true
15
- path_base = "/" + path + "/"
16
- path_id = ids.join(',') if ids.kind_of?(Array)
17
- path_id ||= ids.to_s
18
- path_params = URI.encode_www_form(params)
19
- full_path = path_base + path_id
20
- full_path << "?" + path_params unless path_params.empty?
21
- req = Net::HTTP::Get.new full_path, HEADER.merge({HEADER_API_KEY_PARAM => self.api_key})
22
- response = http.request(req)
23
- response.value
24
- JSON.parse response.body ,object_class: OpenStruct
25
- end
26
-
27
- def method_missing(m, *args, opts, &block)
28
- method = m.to_s
29
- if method[/^search_/]
30
- method[/^search_/] = ""
31
- # If only single string argument passed in args becomes empty
32
- # and string lands in opts
33
- if args.empty?
34
- args = [opts]
35
- opts = {}
36
- end
37
- params = {"search" => args.first}
38
- params = params.merge(opts) if opts
39
- self.get method, nil, params
40
- elsif method[/^count_/]
41
- method[/^count_/] = ""
42
- self.get method, "count", opts
43
- else
44
- self.get method, args, opts
45
- end
46
- end
47
-
48
- end
49
- end