bungie_client 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +12 -24
- data/lib/bungie_client.rb +1 -2
- data/lib/bungie_client/version.rb +1 -1
- data/lib/bungie_client/wrapper.rb +63 -0
- metadata +3 -4
- data/lib/bungie_client/wrappers/default.rb +0 -65
- data/lib/bungie_client/wrappers/user.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d9e596bd5517cf5251a6143166bcbe7f2766218
|
4
|
+
data.tar.gz: c23a7997ea88fbaa849690ab27f3eee8a4b3ccd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 373f0c3db1c20562c0454fbc02026c776b8066a206d07a8d5b530958276b430995aa442e363eecaf623b80bd5537f778beed6b81883e55e1b52d0de02c9cd155
|
7
|
+
data.tar.gz: 6d3440350b42f774be43b7d957288adf1d5aa6e336efda40b34caa805c3f6eda5dfc658a3a9175a97a3c0786810af83b53472adf217524e91a66e9cb1b9e8e54
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 2.1.0 (2017-06-25)
|
4
|
+
|
5
|
+
### Fixes
|
6
|
+
|
7
|
+
* Empty hashes for `BungieClient::Wrapper#call_service` method.
|
8
|
+
|
9
|
+
### Changes
|
10
|
+
|
11
|
+
* Move `Default` class to `BungieClient::Wrapper`.
|
12
|
+
|
13
|
+
### Removed
|
14
|
+
|
15
|
+
* `BungieClient::Wrappers` namespace with `User` class
|
3
16
|
|
4
17
|
## 2.0.0 (2017-06-21)
|
5
18
|
|
@@ -17,5 +30,6 @@
|
|
17
30
|
* Move services generator to Rake tasks.
|
18
31
|
|
19
32
|
### Removed
|
33
|
+
|
20
34
|
* `get_response` and `post_response` methods, now it works in default `get` and `post` method from `BungieClient::Client`.
|
21
35
|
* cookies support in `BungieClient::Client`.
|
data/README.md
CHANGED
@@ -26,24 +26,24 @@ This gem contains two main classes: **BungieClient::Client**, **BungieClient::Wr
|
|
26
26
|
|
27
27
|
It's main class that makes possible to send any requests to Bungie.
|
28
28
|
|
29
|
-
**For this
|
29
|
+
**For this You should initialize your client for the next example:**
|
30
30
|
|
31
31
|
~~~~ruby
|
32
32
|
client = BungieClient::Client.new :api_key => 'YOUR_API_KEY'
|
33
33
|
~~~~
|
34
34
|
|
35
35
|
* The option `api_key` only necessary for this class and API. For getting API key, please visit the [bungie page](https://www.bungie.net/en/user/api).
|
36
|
-
* After it
|
37
|
-
* The full information about classes and modules and their methods
|
36
|
+
* After it You can send your request to [Bungie Endpoint](http://destinydevs.github.io/BungieNetPlatform/docs/Endpoints).
|
37
|
+
* The full information about classes and modules and their methods You can find in yard-comments and [rubydoc](http://www.rubydoc.info/gems/bungie_client).
|
38
38
|
|
39
39
|
#### How it initialized:
|
40
40
|
|
41
|
-
* If
|
41
|
+
* If You want to use private API, You must get [Authorization token](https://www.bungie.net/en/Help/Article/45481) from Bungie Oauth2 and set `token` option.
|
42
42
|
* After this operations your client is done for usage.
|
43
43
|
|
44
44
|
#### Sending requests
|
45
45
|
|
46
|
-
**Now
|
46
|
+
**Now You can send requests, e.g. for finding user information and getting his profile:**
|
47
47
|
|
48
48
|
~~~~ruby
|
49
49
|
client.get "Destiny/SearchDestinyPlayer/2/RuBAN-GT"
|
@@ -51,36 +51,24 @@ client.get "Destiny/SearchDestinyPlayer/2/RuBAN-GT"
|
|
51
51
|
|
52
52
|
#### Note
|
53
53
|
|
54
|
-
* For requests optimization
|
54
|
+
* For requests optimization You should use any caching of your requests.
|
55
55
|
|
56
|
-
### BungieClient::
|
56
|
+
### BungieClient::Wrapper
|
57
57
|
|
58
|
-
If
|
58
|
+
If You don't like long code as for me You should use **BungieClient::Wrapper**. It's class can call api services with dynamically generated methods with snake case like name services. Also it can change url parameters to needed values.
|
59
59
|
|
60
|
-
The initialization of **
|
60
|
+
The initialization of **Wrapper** is similar to **Client**: all arguments of initializer will be passed to **Client** which is class variable of wrapper.
|
61
61
|
|
62
62
|
~~~~ruby
|
63
|
-
wrapper = BungieClient::
|
63
|
+
wrapper = BungieClient::Wrapper.new :api_key => 'YOUR_API_KEY'
|
64
64
|
~~~~
|
65
65
|
|
66
|
-
Now
|
66
|
+
Now You can sending your requests with beautiful and effective code:
|
67
67
|
|
68
68
|
~~~~ruby
|
69
69
|
wrapper.search_destiny_player :membershipType => '2', :displayName => 'RuBAN-GT'
|
70
70
|
~~~~
|
71
71
|
|
72
|
-
If you need **more** you can define your own wrappers such as **Wrappers::User**:
|
73
|
-
|
74
|
-
~~~~ruby
|
75
|
-
user = BungieClient::Wrappers::User.new(
|
76
|
-
:api_key => 'YOUR_API_KEY',
|
77
|
-
:display_name => 'RuBAN-GT',
|
78
|
-
:membership_type => '2'
|
79
|
-
)
|
80
|
-
|
81
|
-
@user.search_destiny_player
|
82
|
-
~~~~
|
83
|
-
|
84
72
|
## Contributing
|
85
73
|
|
86
74
|
Bug reports and pull requests are welcome on GitHub at https://github.com/RuBAN-GT/bungie_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
@@ -91,4 +79,4 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
91
79
|
|
92
80
|
## Fireteam
|
93
81
|
|
94
|
-
If
|
82
|
+
If You want to fight with Oryx with me or create any interesting applications for Destiny, You can add me ([https://www.bungie.net/en/Profile/254/12488384](https://www.bungie.net/en/Profile/254/12488384)).
|
data/lib/bungie_client.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Wrapper class for simple api requests
|
2
|
+
class BungieClient::Wrapper
|
3
|
+
# Initialize wrapper with client
|
4
|
+
#
|
5
|
+
# This initializer create wrapper object with client.
|
6
|
+
# If you `options` contain `:client` key, it will be taken as client object [BungieClient::Client]. Otherwise it will be passed in client initializer.
|
7
|
+
#
|
8
|
+
# @see BungieClient::Client
|
9
|
+
#
|
10
|
+
# @param [BungieClient::Client] client initialized for wrapper
|
11
|
+
# @param [Hash] options for initialization of client
|
12
|
+
def initialize(options = {})
|
13
|
+
if options[:client].nil?
|
14
|
+
@options = options
|
15
|
+
elsif options[:client].is_a? BungieClient::Client
|
16
|
+
@client = options[:client]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get wrapper client
|
21
|
+
#
|
22
|
+
# @return [BungieClient::Client]
|
23
|
+
def client
|
24
|
+
return @client unless @client.nil?
|
25
|
+
|
26
|
+
@client = BungieClient::Client.new @options
|
27
|
+
end
|
28
|
+
|
29
|
+
# Change all url parameters to hash value
|
30
|
+
#
|
31
|
+
# @param [String] url
|
32
|
+
# @param [Hash] params
|
33
|
+
#
|
34
|
+
# @return [String]
|
35
|
+
def fill_url(url, params)
|
36
|
+
params.each do |key, value|
|
37
|
+
url = url.gsub "{#{key}}", value.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
url
|
41
|
+
end
|
42
|
+
|
43
|
+
# Call needed service from services list
|
44
|
+
#
|
45
|
+
# @param [String] service name in snake case
|
46
|
+
# @param [Hash] params service parameters
|
47
|
+
# @param [Hash] options for client request (get/post)
|
48
|
+
#
|
49
|
+
# @return [Hashie::Mash]
|
50
|
+
def call_service(service, params = {}, options = {})
|
51
|
+
service = BungieClient::Service.new service rescue raise NoMethodError
|
52
|
+
|
53
|
+
# change url
|
54
|
+
url = self.fill_url service.endpoint, params
|
55
|
+
|
56
|
+
# send request
|
57
|
+
client.send service.type, url, options
|
58
|
+
end
|
59
|
+
|
60
|
+
def method_missing(*args)
|
61
|
+
call_service args[0].to_s, args[1] || {}, args[2] || {}
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bungie_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Ruban
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -160,8 +160,7 @@ files:
|
|
160
160
|
- lib/bungie_client/service.rb
|
161
161
|
- lib/bungie_client/services.yml
|
162
162
|
- lib/bungie_client/version.rb
|
163
|
-
- lib/bungie_client/
|
164
|
-
- lib/bungie_client/wrappers/user.rb
|
163
|
+
- lib/bungie_client/wrapper.rb
|
165
164
|
- lib/tasks/parse_services.rake
|
166
165
|
- lib/underscore.rb
|
167
166
|
homepage: https://github.com/RuBAN-GT/bungie_client
|
@@ -1,65 +0,0 @@
|
|
1
|
-
# Wrapper class for simple api requests
|
2
|
-
module BungieClient::Wrappers
|
3
|
-
class Default
|
4
|
-
# Initialize wrapper with client
|
5
|
-
#
|
6
|
-
# This initializer create wrapper object with client.
|
7
|
-
# If you `options` contain `:client` key, it will be taken as client object [BungieClient::Client]. Otherwise it will be passed in client initializer.
|
8
|
-
#
|
9
|
-
# @see BungieClient::Client
|
10
|
-
#
|
11
|
-
# @param [BungieClient::Client] client initialized for wrapper
|
12
|
-
# @param [Hash] options for initialization of client
|
13
|
-
def initialize(options = {})
|
14
|
-
if options[:client].nil?
|
15
|
-
@options = options
|
16
|
-
elsif options[:client].is_a? BungieClient::Client
|
17
|
-
@client = options[:client]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# Get wrapper client
|
22
|
-
#
|
23
|
-
# @return [BungieClient::Client]
|
24
|
-
def client
|
25
|
-
return @client unless @client.nil?
|
26
|
-
|
27
|
-
@client = BungieClient::Client.new @options
|
28
|
-
end
|
29
|
-
|
30
|
-
# Change all url parameters to hash value
|
31
|
-
#
|
32
|
-
# @param [String] url
|
33
|
-
# @param [Hash] params
|
34
|
-
#
|
35
|
-
# @return [String]
|
36
|
-
def fill_url(url, params)
|
37
|
-
params.each do |key, value|
|
38
|
-
url = url.gsub "{#{key}}", value.to_s
|
39
|
-
end
|
40
|
-
|
41
|
-
url
|
42
|
-
end
|
43
|
-
|
44
|
-
# Call needed service from services list
|
45
|
-
#
|
46
|
-
# @param [String] service name in snake case
|
47
|
-
# @param [Hash] params service parameters
|
48
|
-
# @param [Hash] options for client request (get/post)
|
49
|
-
#
|
50
|
-
# @return [Hashie::Mash]
|
51
|
-
def call_service(service, params = {}, options = {})
|
52
|
-
service = BungieClient::Service.new service rescue raise NoMethodError
|
53
|
-
|
54
|
-
# change url
|
55
|
-
url = self.fill_url service.endpoint, params
|
56
|
-
|
57
|
-
# send request
|
58
|
-
client.send service.type, url, options
|
59
|
-
end
|
60
|
-
|
61
|
-
def method_missing(*args)
|
62
|
-
call_service args[0].to_s, args[1], args[2]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module BungieClient::Wrappers
|
2
|
-
class User < Default
|
3
|
-
attr_reader :membership_type, :display_name
|
4
|
-
|
5
|
-
# Initialize wrapper with user's preset
|
6
|
-
#
|
7
|
-
# @note maybe add the `destiny_membership_id` as an alternative to `display_name`
|
8
|
-
#
|
9
|
-
# @option options [Integer] :membership_type Platform type number (xbox - 1, playstation - 2, all - 256)
|
10
|
-
# @option options [String] :display_name Simple user name
|
11
|
-
def initialize(options)
|
12
|
-
super
|
13
|
-
|
14
|
-
# set membershipType
|
15
|
-
if %w(1 2 256).include? options[:membership_type].to_s
|
16
|
-
@membership_type = options[:membership_type].to_s
|
17
|
-
else
|
18
|
-
@membership_type = '256'
|
19
|
-
end
|
20
|
-
|
21
|
-
# set displayName
|
22
|
-
if options[:display_name].is_a? String
|
23
|
-
@display_name = options[:display_name]
|
24
|
-
else
|
25
|
-
raise 'You must set user display name'
|
26
|
-
end
|
27
|
-
|
28
|
-
# set destinyMembershipId if needed
|
29
|
-
@destiny_membership_id = options[:destiny_membership_id] unless options[:destiny_membership_id].nil?
|
30
|
-
end
|
31
|
-
|
32
|
-
# Get DestinyMembershipId of selected user
|
33
|
-
def destiny_membership_id
|
34
|
-
return @destiny_membership_id unless @destiny_membership_id.nil?
|
35
|
-
|
36
|
-
@destiny_membership_id = call_service(
|
37
|
-
'get_membership_id_by_display_name',
|
38
|
-
{
|
39
|
-
:displayName => @display_name,
|
40
|
-
:membershipType => @membership_type
|
41
|
-
}
|
42
|
-
)
|
43
|
-
end
|
44
|
-
|
45
|
-
def fill_url(url, params)
|
46
|
-
params = {} unless params.is_a? Hash
|
47
|
-
|
48
|
-
params[:displayName] = @display_name
|
49
|
-
params[:membershipType] = @membership_type
|
50
|
-
params[:destinyMembershipId] = destiny_membership_id if url.include? '{destinyMembershipId}'
|
51
|
-
params[:membershipId] = destiny_membership_id if url.include? '{membershipId}'
|
52
|
-
|
53
|
-
super
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|