bungie_client 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/bungie_client.gemspec +1 -2
- data/lib/bungie_client.rb +1 -2
- data/lib/bungie_client/client.rb +11 -20
- data/lib/bungie_client/services.yml +10 -14
- data/lib/bungie_client/version.rb +1 -1
- metadata +18 -6
- data/examples/auth_usage.rb +0 -10
- data/lib/bungie_client/auth.rb +0 -140
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e72c44c0ee045ada431e0375c8224a5950399de
|
4
|
+
data.tar.gz: 881799831b0c3b516246ac2b4e79eaa3b7817874
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca54892aeeb1ca4e31e06e5f21662ef0af903ad0c1b7e0306f9aa74a60fcedea2e9392ddbc551ff225c5c1646f15d97484926aef197cf9c0b601d4f8b9bb9162
|
7
|
+
data.tar.gz: c78371d1124a965edc68a385f5e7f5af79414814a182f0ee7cf91d57588171264cc4e86648b1362b4a13ca63e3bae7b5f0fef1a43d258d682fb25544acffd1b2
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/bungie_client.svg)](https://badge.fury.io/rb/bungie_client)
|
2
|
+
[![Build Status](https://travis-ci.org/RuBAN-GT/bungie_client.svg?branch=master)](https://travis-ci.org/RuBAN-GT/bungie_client)
|
2
3
|
|
3
4
|
# Bungie Client
|
4
5
|
|
@@ -122,4 +123,4 @@ If you want to fight with Oryx with me or create any interesting applications fo
|
|
122
123
|
|
123
124
|
## Note
|
124
125
|
|
125
|
-
* In the source code you can fine `services_parser.rb`. It's script created for getting full list of Bungie API services, for result it generates `services.yml` in lib.
|
126
|
+
* In the source code you can fine `services_parser.rb`. It's script created for getting full list of Bungie API services, for result it generates `services.yml` in lib.
|
data/bungie_client.gemspec
CHANGED
@@ -18,12 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = "~> 2.3.0"
|
22
|
-
|
23
21
|
spec.add_development_dependency "bundler", "~> 1.12"
|
24
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
23
|
spec.add_development_dependency "rspec", "~> 3.0"
|
26
24
|
|
25
|
+
spec.add_runtime_dependency "multi_json", "~> 1.12"
|
27
26
|
spec.add_runtime_dependency "hashie", "~> 3.4"
|
28
27
|
spec.add_runtime_dependency 'mechanize', "~> 2.7", ">= 2.7.0"
|
29
28
|
end
|
data/lib/bungie_client.rb
CHANGED
data/lib/bungie_client/client.rb
CHANGED
@@ -18,7 +18,7 @@ class BungieClient::Client
|
|
18
18
|
# @return [Hashie::Mash]
|
19
19
|
def self.parse_response(response)
|
20
20
|
if !response.nil? && response != ''
|
21
|
-
response =
|
21
|
+
response = MultiJson.load response rescue return Hashie::Mash.new
|
22
22
|
|
23
23
|
if response.is_a?(Hash) && !response['Response'].nil? && response['ErrorCode'] == 1
|
24
24
|
response = Hashie::Mash.new response
|
@@ -45,9 +45,7 @@ class BungieClient::Client
|
|
45
45
|
# @param [Hash] options
|
46
46
|
# @option options [String] :api_key
|
47
47
|
# @option options [Array|CookieJar] :cookies with [HTTP::Cookie] or [CookieJar]
|
48
|
-
# @option options [String] :
|
49
|
-
# @option options [String] :password password of user, necessary if set :authenticate
|
50
|
-
# @option options [String] :type of account, it can be 'psn' or 'live'
|
48
|
+
# @option options [String] :token is authorization token from new oauth2
|
51
49
|
def initialize(options)
|
52
50
|
# checking options and @api_key
|
53
51
|
raise 'Wrong options: It must be Hash.' unless options.is_a? Hash
|
@@ -58,31 +56,21 @@ class BungieClient::Client
|
|
58
56
|
@api_key = options[:api_key].to_s
|
59
57
|
end
|
60
58
|
|
59
|
+
# set token
|
60
|
+
@token = options[:token].to_s unless options[:token].nil?
|
61
|
+
|
61
62
|
# init @agent
|
62
63
|
@agent = Mechanize.new do |config|
|
63
64
|
config.read_timeout = 5
|
64
65
|
end
|
65
66
|
|
66
67
|
# merge cookies with options
|
67
|
-
|
68
|
+
unless options[:cookies].nil?
|
68
69
|
cookies = (options[:cookies].is_a? CookieJar) ? options[:cookies].cookies : options[:cookies]
|
69
70
|
|
70
71
|
cookies.each do |cookie|
|
71
72
|
@agent.cookie_jar.add cookie
|
72
73
|
end
|
73
|
-
end unless options[:cookies].nil?
|
74
|
-
|
75
|
-
# make authentication and save new cookies in client
|
76
|
-
unless options[:username].nil? || options[:password].nil?
|
77
|
-
jar = BungieClient::Auth.auth options[:username].to_s, options[:password].to_s, (options[:type].to_s || 'psn')
|
78
|
-
|
79
|
-
if jar.nil?
|
80
|
-
raise "Wrong authentication. Check your account data."
|
81
|
-
else
|
82
|
-
jar.cookies.each do |cookie|
|
83
|
-
@agent.cookie_jar.add cookie
|
84
|
-
end
|
85
|
-
end
|
86
74
|
end
|
87
75
|
end
|
88
76
|
|
@@ -132,10 +120,13 @@ class BungieClient::Client
|
|
132
120
|
|
133
121
|
# Headers for requests
|
134
122
|
def headers
|
135
|
-
{
|
123
|
+
headers = {
|
136
124
|
'Accept' => 'json',
|
137
|
-
'Content-Type' => 'json',
|
125
|
+
'Content-Type' => 'application/json',
|
138
126
|
'X-API-Key' => @api_key
|
139
127
|
}
|
128
|
+
headers['Authorization'] = "Bearer #{@token}" unless @token.nil?
|
129
|
+
|
130
|
+
headers
|
140
131
|
end
|
141
132
|
end
|
@@ -118,7 +118,7 @@ get_notification_settings:
|
|
118
118
|
get_partnerships:
|
119
119
|
:name: GetPartnerships
|
120
120
|
:method: get
|
121
|
-
:endpoint: "/User/{
|
121
|
+
:endpoint: "/User/{membershipId}/Partnerships/"
|
122
122
|
get_platform_api_keys_for_user:
|
123
123
|
:name: GetPlatformApiKeysForUser
|
124
124
|
:method: get
|
@@ -1107,10 +1107,6 @@ verify_age:
|
|
1107
1107
|
:name: VerifyAge
|
1108
1108
|
:method: post
|
1109
1109
|
:endpoint: "/Tokens/VerifyAge/"
|
1110
|
-
buy_item:
|
1111
|
-
:name: BuyItem
|
1112
|
-
:method: post
|
1113
|
-
:endpoint: "/Destiny/BuyItem/"
|
1114
1110
|
equip_item:
|
1115
1111
|
:name: EquipItem
|
1116
1112
|
:method: post
|
@@ -1335,10 +1331,6 @@ get_vendor_summaries_for_current_character:
|
|
1335
1331
|
:name: GetVendorSummariesForCurrentCharacter
|
1336
1332
|
:method: get
|
1337
1333
|
:endpoint: "/Destiny/{membershipType}/MyAccount/Character/{characterId}/Vendors/Summaries/"
|
1338
|
-
refund_item:
|
1339
|
-
:name: RefundItem
|
1340
|
-
:method: post
|
1341
|
-
:endpoint: "/Destiny/{param1}/RefundItem/"
|
1342
1334
|
search_destiny_player:
|
1343
1335
|
:name: SearchDestinyPlayer
|
1344
1336
|
:method: get
|
@@ -1374,7 +1366,7 @@ edit_content:
|
|
1374
1366
|
get_admin_community_live_statuses:
|
1375
1367
|
:name: GetAdminCommunityLiveStatuses
|
1376
1368
|
:method: get
|
1377
|
-
:endpoint: "/CommunityContent/Live/Admin/{param1}/{param2}/"
|
1369
|
+
:endpoint: "/CommunityContent/Live/Admin/{param1}/{param2}/{param3}/"
|
1378
1370
|
get_approval_queue:
|
1379
1371
|
:name: GetApprovalQueue
|
1380
1372
|
:method: get
|
@@ -1390,19 +1382,23 @@ get_community_featured_activity_modes:
|
|
1390
1382
|
get_community_live_statuses:
|
1391
1383
|
:name: GetCommunityLiveStatuses
|
1392
1384
|
:method: get
|
1393
|
-
:endpoint: "/CommunityContent/Live/All/{
|
1385
|
+
:endpoint: "/CommunityContent/Live/All/{partnershipType}/{communityStatusSort}/{page}/"
|
1394
1386
|
get_community_live_statuses_for_clanmates:
|
1395
1387
|
:name: GetCommunityLiveStatusesForClanmates
|
1396
1388
|
:method: get
|
1397
|
-
:endpoint: "/CommunityContent/Live/Clan/{
|
1389
|
+
:endpoint: "/CommunityContent/Live/Clan/{partnershipType}/{communityStatusSort}/{page}/"
|
1398
1390
|
get_community_live_statuses_for_friends:
|
1399
1391
|
:name: GetCommunityLiveStatusesForFriends
|
1400
1392
|
:method: get
|
1401
|
-
:endpoint: "/CommunityContent/Live/Friends/{
|
1393
|
+
:endpoint: "/CommunityContent/Live/Friends/{partnershipType}/{communityStatusSort}/{page}/"
|
1402
1394
|
get_featured_community_live_statuses:
|
1403
1395
|
:name: GetFeaturedCommunityLiveStatuses
|
1404
1396
|
:method: get
|
1405
|
-
:endpoint: "/CommunityContent/Live/Featured/{
|
1397
|
+
:endpoint: "/CommunityContent/Live/Featured/{partnershipType}/{communityStatusSort}/{page}/"
|
1398
|
+
get_streaming_status_for_member:
|
1399
|
+
:name: GetStreamingStatusForMember
|
1400
|
+
:method: get
|
1401
|
+
:endpoint: "/CommunityContent/Live/Users/{partnershipType}/{membershipType}/{membershipId}/"
|
1406
1402
|
submit_content:
|
1407
1403
|
:name: SubmitContent
|
1408
1404
|
:method: post
|
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.0
|
4
|
+
version: 1.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-01-
|
11
|
+
date: 2017-01-26 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: multi_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.12'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.12'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: hashie
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,11 +120,9 @@ files:
|
|
106
120
|
- bin/console
|
107
121
|
- bin/setup
|
108
122
|
- bungie_client.gemspec
|
109
|
-
- examples/auth_usage.rb
|
110
123
|
- examples/client_usage.rb
|
111
124
|
- examples/wrapper_usage.rb
|
112
125
|
- lib/bungie_client.rb
|
113
|
-
- lib/bungie_client/auth.rb
|
114
126
|
- lib/bungie_client/client.rb
|
115
127
|
- lib/bungie_client/service.rb
|
116
128
|
- lib/bungie_client/services.yml
|
@@ -129,9 +141,9 @@ require_paths:
|
|
129
141
|
- lib
|
130
142
|
required_ruby_version: !ruby/object:Gem::Requirement
|
131
143
|
requirements:
|
132
|
-
- - "
|
144
|
+
- - ">="
|
133
145
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
146
|
+
version: '0'
|
135
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
148
|
requirements:
|
137
149
|
- - ">="
|
data/examples/auth_usage.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
-
|
3
|
-
require 'bungie_client'
|
4
|
-
|
5
|
-
# Get bungie cookies
|
6
|
-
jar = BungieClient::Auth.auth 'example@mail.com', 'example', 'psn'
|
7
|
-
p (jar.nil?) ? 0 : jar.cookies.length
|
8
|
-
|
9
|
-
# Check cookies and authentication
|
10
|
-
p BungieClient::Auth.auth_possible? (jar || [])
|
data/lib/bungie_client/auth.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
# Module Auth with two methods: authentication in bungie.net by PSN or Xbox Live and checking this authentication with cookies that was returned early.
|
2
|
-
module BungieClient::Auth
|
3
|
-
class << self
|
4
|
-
# Check cookies for private requests
|
5
|
-
#
|
6
|
-
# @param [Array] cookies with [HTTP::Cookie]
|
7
|
-
# @param [Boolean] raise cookie errors
|
8
|
-
#
|
9
|
-
# @return [Boolean]
|
10
|
-
def valid_cookies?(cookies, raise = false)
|
11
|
-
if cookies.is_a? Mechanize::CookieJar
|
12
|
-
cookies = cookies.cookies
|
13
|
-
elsif !(cookies.is_a?(Array) && cookies.all? { |c| c.is_a? HTTP::Cookie })
|
14
|
-
raise "Wrong cookie option: It must be Array with HTTP::Cookie elements or CookieJar." if raise
|
15
|
-
|
16
|
-
return false
|
17
|
-
end
|
18
|
-
|
19
|
-
needed = %w(bungled bungleatk bungles)
|
20
|
-
cookies.each do |cookie|
|
21
|
-
if needed.include?(cookie.name) && cookie.expired? == false
|
22
|
-
needed.delete cookie.name
|
23
|
-
|
24
|
-
return true if needed.length == 0
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
(raise) ? raise("Your argument doesn't have all needed cookies for private requests #{needed.join ','}.") : false
|
29
|
-
end
|
30
|
-
|
31
|
-
# Full authentication of user
|
32
|
-
#
|
33
|
-
# @param [String] username user email for auth
|
34
|
-
# @param [String] password user password for auth
|
35
|
-
# @param [String] type can be psn or live
|
36
|
-
#
|
37
|
-
# @return [Mechanize::CookieJar|nil]
|
38
|
-
def auth(username, password, type = 'psn')
|
39
|
-
# client init
|
40
|
-
agent = Mechanize.new do |config|
|
41
|
-
config.open_timeout = 60
|
42
|
-
config.read_timeout = 60
|
43
|
-
config.idle_timeout = 120
|
44
|
-
end
|
45
|
-
|
46
|
-
# getting index page
|
47
|
-
agent.get 'https://www.bungie.net/' do |page|
|
48
|
-
result = nil
|
49
|
-
link = page.link_with :text => search_query(type)
|
50
|
-
|
51
|
-
unless link.nil?
|
52
|
-
# call auth page
|
53
|
-
login = agent.click link
|
54
|
-
|
55
|
-
# sending form for sony or ms
|
56
|
-
if type == 'psn'
|
57
|
-
form = login.forms.first
|
58
|
-
unless form.nil?
|
59
|
-
name = form.field_with(:type => 'email')
|
60
|
-
pass = form.field_with(:type => 'password')
|
61
|
-
|
62
|
-
if !name.nil? && !pass.nil?
|
63
|
-
name.value = username
|
64
|
-
pass.value = password
|
65
|
-
|
66
|
-
result = form.click_button
|
67
|
-
end
|
68
|
-
end
|
69
|
-
else
|
70
|
-
# ms wanted enabled js, but we can send form without it
|
71
|
-
ppft = login.body.match(/name\="PPFT"(.*)value\="(.*?)"/)
|
72
|
-
url = login.body.match(/urlPost\:'(.*?)'/)
|
73
|
-
|
74
|
-
if !ppft.nil? && !url.nil?
|
75
|
-
result = agent.post url.to_a.last,
|
76
|
-
'login' => username,
|
77
|
-
'passwd' => password,
|
78
|
-
'KMSI' => 1,
|
79
|
-
'PPFT' => ppft.to_a.last
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# if result not nil and after authentication we returned to bungie, all ok
|
85
|
-
if !result.nil? && result.uri.to_s.include?('?code')
|
86
|
-
needed = %w(bungled bungleatk bungledid bungles)
|
87
|
-
output = Mechanize::CookieJar.new
|
88
|
-
|
89
|
-
agent.cookies.each do |cookie|
|
90
|
-
output.add cookie if needed.include? cookie.name
|
91
|
-
end
|
92
|
-
|
93
|
-
return output
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
nil
|
98
|
-
end
|
99
|
-
|
100
|
-
# Try authenticate with cookies
|
101
|
-
#
|
102
|
-
# @param [Array|CookieJar] cookies array with [HTTP::Cookie] or [CookieJar]
|
103
|
-
#
|
104
|
-
# @return [Boolean]
|
105
|
-
def auth_possible?(cookies)
|
106
|
-
agent = Mechanize.new
|
107
|
-
|
108
|
-
valid_cookies? cookies, true
|
109
|
-
|
110
|
-
if cookies.is_a? Array
|
111
|
-
cookies.each do |cookie|
|
112
|
-
agent.cookie_jar.add cookie
|
113
|
-
end
|
114
|
-
else
|
115
|
-
agent.cookie_jar = cookies
|
116
|
-
end
|
117
|
-
|
118
|
-
result = nil
|
119
|
-
agent.get 'https://www.bungie.net/' do |page|
|
120
|
-
link = page.link_with :text => search_query('psn')
|
121
|
-
|
122
|
-
result = agent.click link unless link.nil?
|
123
|
-
end
|
124
|
-
|
125
|
-
!result.nil? && result.uri.host == "www.bungie.net"
|
126
|
-
end
|
127
|
-
|
128
|
-
protected
|
129
|
-
|
130
|
-
def search_query(type)
|
131
|
-
if type == 'psn'
|
132
|
-
'PlayStation Network'
|
133
|
-
elsif type == 'live'
|
134
|
-
'Xbox Live'
|
135
|
-
else
|
136
|
-
raise 'Wrong account type!'
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|