bungie_client 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
- module BungieClient
2
- VERSION = '1.1.1'
3
- end
1
+ module BungieClient
2
+ VERSION = '2.0.0'
3
+ end
@@ -1,84 +1,65 @@
1
- # Wrapper class for simple api requests
2
- module BungieClient::Wrappers
3
- class Default
4
- # Get list of services
5
- #
6
- # @see http://destinydevs.github.io/BungieNetPlatform/docs/Endpoints
7
- #
8
- # @return [Hash]
9
- def self.services
10
- return @services unless @services.nil?
11
-
12
- @services = YAML.load_file "#{File.dirname(__FILE__)}/../services.yml" || {}
13
- end
14
-
15
- # Initialize wrapper with client
16
- #
17
- # This initializer create wrapper object with client.
18
- # If you `options` contain `:client` key, it will be taken as client object [BungieClient::Client]. Otherwise it will be passed in client initializer.
19
- #
20
- # @see BungieClient::Client
21
- #
22
- # @param [Hash] options
23
- def initialize(options)
24
- if options[:client].nil?
25
- @options = options
26
- elsif options[:client].is_a? BungieClient::Client
27
- @client = options[:client]
28
- end
29
- end
30
-
31
- # Get wrapper client
32
- #
33
- # @return [BungieClient::Client]
34
- def client
35
- return @client unless @client.nil?
36
-
37
- @client = BungieClient::Client.new @options
38
- @options = nil
39
-
40
- @client
41
- end
42
-
43
- # Change all url parameters to hash value
44
- #
45
- # @param [String] url
46
- # @param [Hash] params
47
- #
48
- # @return [String]
49
- def fill_url(url, params)
50
- params.each do |key, value|
51
- url = url.gsub "{#{key}}", value.to_s
52
- end unless params.nil?
53
-
54
- url
55
- end
56
-
57
- # Call needed service from services list
58
- #
59
- # @param [String] service name in snake case
60
- # @param [Hash] params service parameters
61
- # @param [Hash] options for client request (get/post)
62
- #
63
- # @return [Hashie::Mash]
64
- def call_service(service, params = {}, options = {})
65
- # try to find service
66
- service = self.class.services[service]
67
-
68
- raise NoMethodError if service.nil?
69
-
70
- # init service
71
- service = BungieClient::Service.new service
72
-
73
- # change url
74
- url = self.fill_url service.endpoint, params
75
-
76
- # send request
77
- client.send "#{service.method_type}_response", url, options
78
- end
79
-
80
- def method_missing(*args)
81
- call_service args[0].to_s, args[1], args[2]
82
- end
83
- end
84
- end
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 +1,56 @@
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
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
@@ -0,0 +1,35 @@
1
+ require 'yaml'
2
+ require 'hashie'
3
+ require 'nokogiri'
4
+ require 'open-uri'
5
+ require 'underscore'
6
+
7
+ # This task can parse the list of bungie services from *destinydevs.github.io* for client.
8
+ task :parse_services do
9
+ # preset
10
+ services = {}
11
+ response = Nokogiri::HTML open('http://destinydevs.github.io/BungieNetPlatform/docs/Endpoints')
12
+
13
+ # get services
14
+ response.search('.container .table tbody tr').each do |tr|
15
+ tds = tr.search 'td'
16
+
17
+ next if tds.nil? || tds[1].nil?
18
+
19
+ service = {
20
+ :name => tds[1].text,
21
+ :method => (tds[0]&.text.downcase || 'get'),
22
+ :endpoint => (tds[2]&.text || '')
23
+ }
24
+ service[:endpoint].slice! 0
25
+
26
+ services[tds[1].text.underscore] = service
27
+ end
28
+
29
+ # save yaml
30
+ File.open "#{File.dirname(__FILE__)}/../bungie_client/services.yml", 'w' do |f|
31
+ f.write services.to_yaml
32
+ end
33
+
34
+ p 'Services were generated...'
35
+ end
data/lib/underscore.rb CHANGED
@@ -1,10 +1,10 @@
1
- class String
2
- # Transform string to snake case
3
- def underscore
4
- self.gsub(/::/, '/').
5
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
6
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
7
- tr("- ", "_").
8
- downcase
9
- end
1
+ class String
2
+ # Transform string to snake case
3
+ def underscore
4
+ self.gsub(/::/, '/').
5
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
6
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
7
+ tr("- ", "_").
8
+ downcase
9
+ end
10
10
  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: 1.1.1
4
+ version: 2.0.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-01-28 00:00:00.000000000 Z
11
+ date: 2017-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: multi_json
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -81,25 +95,47 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '3.4'
83
97
  - !ruby/object:Gem::Dependency
84
- name: mechanize
98
+ name: httpclient
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '2.7'
90
- - - ">="
103
+ version: '2.8'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.8'
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
91
116
  - !ruby/object:Gem::Version
92
- version: 2.7.0
117
+ version: '0.12'
93
118
  type: :runtime
94
119
  prerelease: false
95
120
  version_requirements: !ruby/object:Gem::Requirement
96
121
  requirements:
97
122
  - - "~>"
98
123
  - !ruby/object:Gem::Version
99
- version: '2.7'
100
- - - ">="
124
+ version: '0.12'
125
+ - !ruby/object:Gem::Dependency
126
+ name: faraday_middleware
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
101
137
  - !ruby/object:Gem::Version
102
- version: 2.7.0
138
+ version: '0'
103
139
  description: This gem makes possible to use Bungie API (and Destiny API too). It can
104
140
  be useful, if you decide create your application for Destiny Game (https://www.bungie.net/en/pub/AboutDestiny).
105
141
  email:
@@ -110,6 +146,7 @@ extra_rdoc_files: []
110
146
  files:
111
147
  - ".gitignore"
112
148
  - ".travis.yml"
149
+ - CHANGELOG.md
113
150
  - CODE_OF_CONDUCT.md
114
151
  - Gemfile
115
152
  - LICENSE.txt
@@ -118,8 +155,6 @@ files:
118
155
  - bin/console
119
156
  - bin/setup
120
157
  - bungie_client.gemspec
121
- - examples/client_usage.rb
122
- - examples/wrapper_usage.rb
123
158
  - lib/bungie_client.rb
124
159
  - lib/bungie_client/client.rb
125
160
  - lib/bungie_client/service.rb
@@ -127,8 +162,8 @@ files:
127
162
  - lib/bungie_client/version.rb
128
163
  - lib/bungie_client/wrappers/default.rb
129
164
  - lib/bungie_client/wrappers/user.rb
165
+ - lib/tasks/parse_services.rake
130
166
  - lib/underscore.rb
131
- - services_parser.rb
132
167
  homepage: https://github.com/RuBAN-GT/bungie_client
133
168
  licenses:
134
169
  - MIT
@@ -1,16 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
-
3
- require 'bungie_client'
4
-
5
- # init client
6
- client = BungieClient::Client.new(
7
- :api_key => 'YOUR_API_KEY'
8
- )
9
-
10
- # search account
11
- s = client.get_response "Destiny/SearchDestinyPlayer/2/RuBAN-GT"
12
-
13
- p s = s.first if !s.nil? && s.length == 1
14
-
15
- # get profile with characters
16
- p client.get_response "Destiny/#{s['membershipType']}/Account/#{s['membershipId']}" unless s.nil?