igdb_client 0.5.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a70dde7eec9c2dcd49f0d78d45e276da1d82d7b92b75f70de72a8ba15c924fde
4
+ data.tar.gz: f6b0fca3ff708727484dfe3e681d623a8bce7ee552e791c0b1e8b5e822898b01
5
+ SHA512:
6
+ metadata.gz: ab20081e602219067565591de03b7094161f136bcc3b41c6621430eb27e08a7ae3881b19ebfe1c24447c228103cbb9600f55583ba4d2a32888c0dfb23e0ef2d8
7
+ data.tar.gz: 2be9be28b1fdac117d86417d5e7a13bd43431b08185317bd0987cfb2bf1965fdea81bf93328c94eda6908681a2116c19c596dd945812bf1f364a05cb7efb206a
@@ -0,0 +1,56 @@
1
+ # igdb_client
2
+ Ruby client interface for IGDB API
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.
7
+
8
+ The structure of queries and results matches the [api documentaion.](https://igdb.github.io/api/)
9
+
10
+ ##### Instance
11
+ ```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"
23
+
24
+ # to count number of resources matched, put count_ before resource name
25
+ client.count_games {"filter[rating][gt]" => 75}
26
+
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
+ ```
32
+
33
+
34
+
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"}
45
+
46
+ # to run a text search on a resource, put search_ before resource name
47
+ IGDB::API.search_games "ibb and obb"
48
+
49
+ # to count number of resources matched, put count_ before resource name
50
+ IGDB::API.count_games {"filter[rating][gt]" => 75}
51
+
52
+ # Access retrieved data by using methods matching fields of data
53
+ results = IGDB::API.platform 2
54
+ results[0].name
55
+ results[0].summary
56
+ ```
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,49 @@
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
@@ -0,0 +1,2 @@
1
+ require 'igdb/api'
2
+ require 'igdb/client'
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: igdb_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Abdulla Bubshait
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Client for the Internet Game Database
14
+ email:
15
+ - darkstego@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - lib/igdb/api.rb
22
+ - lib/igdb/client.rb
23
+ - lib/igdb/connection.rb
24
+ - lib/igdb_client.rb
25
+ homepage: https://github.com/darkstego/igdb_client
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.7.5
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Ruby IGDB API.
49
+ test_files: []