gamewisp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/bin/console +24 -0
- data/bin/setup +8 -0
- data/gamewisp.gemspec +30 -0
- data/lib/gamewisp.rb +25 -0
- data/lib/gamewisp/authorizer.rb +128 -0
- data/lib/gamewisp/client.rb +76 -0
- data/lib/gamewisp/server.rb +82 -0
- data/lib/gamewisp/token_store.rb +87 -0
- data/lib/gamewisp/version.rb +3 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf0aa20633ea9cea62bff4ece38954eea39a1768
|
4
|
+
data.tar.gz: e7c93437b6309b8c3b09c82cd10f3c8db3b49a82
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a6c4168986a17cbe9ba362e36f80afe67fac79f38a4a9a2d2c5ab7f147860c474c3b079ac5e8e58091cbf2d52013290e15417690ab7be575ae8a4a7b45b3fefc
|
7
|
+
data.tar.gz: 6288cb3d946cc481adfabfe9742487d1c69bbf27a9468f47147bb3bb06bf05744a3abf05b0d306990f498e9827204c9bc9424b235b5708081b352b29a3071c46
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Gem build dir
|
2
|
+
/pkg/
|
3
|
+
|
4
|
+
# Rspec/testing files
|
5
|
+
/spec/reports/
|
6
|
+
/spec/examples.txt
|
7
|
+
/test/tmp/
|
8
|
+
/test/version_tmp/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
# Used by dotenv library to load environment variables.
|
12
|
+
# .env
|
13
|
+
.envsetup
|
14
|
+
|
15
|
+
## Documentation cache and generated files:
|
16
|
+
/.yardoc/
|
17
|
+
/_yardoc/
|
18
|
+
/doc/
|
19
|
+
/rdoc/
|
20
|
+
/coverage/
|
21
|
+
|
22
|
+
## Environment normalization:
|
23
|
+
/.bundle/
|
24
|
+
/vendor/bundle
|
25
|
+
/lib/bundler/man/
|
26
|
+
/.bin/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
Gemfile.lock
|
31
|
+
.ruby-version
|
32
|
+
.ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Jeff McAffee
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Gamewisp
|
2
|
+
|
3
|
+
A ruby Gamewisp API library.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'gamewisp'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install gamewisp
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Testing
|
32
|
+
|
33
|
+
`guard` is supported for testing submon.
|
34
|
+
|
35
|
+
To successfully run the gamewisp tests, you'll need your gamewisp API key.
|
36
|
+
Create a file named `.envsetup` in the project root containing the following:
|
37
|
+
|
38
|
+
#!/bin/bash
|
39
|
+
# vi: ft=shell
|
40
|
+
|
41
|
+
export GAMEWISP_APP=YOUR APP NAME HERE
|
42
|
+
export GAMEWISP_ID=YOUR ID HERE
|
43
|
+
export GAMEWISP_SECRET=YOUR SECRET HERE
|
44
|
+
export GAMEWISP_ENDPOINT_HOST=localhost
|
45
|
+
export GAMEWISP_ENDPOINT_PORT=8080
|
46
|
+
|
47
|
+
Replace `YOUR * HERE` with your values and save it.
|
48
|
+
|
49
|
+
Before running tests, in the terminal you'll start the tests from,
|
50
|
+
source `.envsetup` file, then run your tests.
|
51
|
+
The tests will look for the API key in the environment variables.
|
52
|
+
|
53
|
+
$ source ./.envsetup
|
54
|
+
$ bundle exec rspec
|
55
|
+
|
56
|
+
Or, if using guard:
|
57
|
+
|
58
|
+
$ source ./.envsetup
|
59
|
+
$ bundle exec guard
|
60
|
+
|
61
|
+
`.envsetup` is ignored in `.gitignore` so you don't have to worry about your
|
62
|
+
API key getting uploaded/committed to the repo.
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jmcaffee/gamewisp.
|
67
|
+
|
68
|
+
|
69
|
+
## License
|
70
|
+
|
71
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
72
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gamewisp"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
def client
|
10
|
+
@client ||= Gamewisp::Client.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_auth
|
14
|
+
client.authorize
|
15
|
+
end
|
16
|
+
|
17
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
18
|
+
require "pry"
|
19
|
+
Pry.start
|
20
|
+
|
21
|
+
#require "irb"
|
22
|
+
#IRB.start
|
23
|
+
#
|
24
|
+
|
data/bin/setup
ADDED
data/gamewisp.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gamewisp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gamewisp"
|
8
|
+
spec.version = Gamewisp::VERSION
|
9
|
+
spec.authors = ["Jeff McAffee"]
|
10
|
+
spec.email = ["jeff@ktechsystems.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{GameWisp API ruby library}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/jmcaffee/gamewisp"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
|
27
|
+
spec.add_dependency "oauth2", "~> 1.2"
|
28
|
+
spec.add_dependency "httparty"
|
29
|
+
spec.add_dependency "json", "~> 2.0"
|
30
|
+
end
|
data/lib/gamewisp.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "gamewisp/version"
|
2
|
+
|
3
|
+
module Gamewisp
|
4
|
+
class GamewispClientError < StandardError
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
if ENV["DEBUG"] and ENV["DEBUG"] == "1"
|
9
|
+
$DEBUG = true
|
10
|
+
end
|
11
|
+
|
12
|
+
def dbg msg, other = nil
|
13
|
+
if $DEBUG
|
14
|
+
puts msg
|
15
|
+
unless other.nil?
|
16
|
+
puts other
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'gamewisp/token_store'
|
22
|
+
require 'gamewisp/authorizer'
|
23
|
+
require 'gamewisp/server'
|
24
|
+
require 'gamewisp/client'
|
25
|
+
|
@@ -0,0 +1,128 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: authorizer.rb
|
3
|
+
# Purpose:: Gamewisp OAuth Authorizer
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 11/07/2016
|
6
|
+
# Copyright:: Copyright (c) 2016, kTech Systems LLC. All rights reserved.
|
7
|
+
# Website:: http://ktechsystems.com
|
8
|
+
##############################################################################
|
9
|
+
|
10
|
+
require 'json/pure'
|
11
|
+
require 'httparty'
|
12
|
+
|
13
|
+
module Gamewisp
|
14
|
+
class Authorizer
|
15
|
+
|
16
|
+
attr_accessor :token_store
|
17
|
+
attr_accessor :gamewisp_url
|
18
|
+
attr_accessor :authorize_path
|
19
|
+
attr_accessor :redirect_uri
|
20
|
+
attr_accessor :host
|
21
|
+
attr_accessor :port
|
22
|
+
attr_accessor :scopes
|
23
|
+
attr_accessor :state
|
24
|
+
|
25
|
+
|
26
|
+
# Only works if this class is derived (includes) HTTParty
|
27
|
+
#
|
28
|
+
#if ENV["DEBUG"]
|
29
|
+
# debug_output $stdout
|
30
|
+
#end
|
31
|
+
|
32
|
+
def initialize state, store
|
33
|
+
self.token_store = store
|
34
|
+
|
35
|
+
self.gamewisp_url = 'api.gamewisp.com'
|
36
|
+
self.authorize_path = "/pub/v1/oauth/authorize"
|
37
|
+
self.host = token_store.endpoint_host
|
38
|
+
self.port = token_store.endpoint_port
|
39
|
+
self.redirect_uri = "http://#{host}:#{port}"
|
40
|
+
|
41
|
+
self.scopes = "read_only,subscriber_read_full,user_read"
|
42
|
+
self.state = state
|
43
|
+
end
|
44
|
+
|
45
|
+
def app_authorization_url
|
46
|
+
params = {
|
47
|
+
response_type: "code",
|
48
|
+
client_id: token_store.client_id,
|
49
|
+
redirect_uri: redirect_uri,
|
50
|
+
scope: scopes,
|
51
|
+
state: state,
|
52
|
+
}
|
53
|
+
|
54
|
+
url = {
|
55
|
+
host: gamewisp_url,
|
56
|
+
path: authorize_path,
|
57
|
+
query: URI.encode_www_form(params)
|
58
|
+
}
|
59
|
+
|
60
|
+
return URI::HTTPS.build(url)
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_server_instance
|
64
|
+
return Server.new(port, state)
|
65
|
+
end
|
66
|
+
|
67
|
+
def renew_tokens_with_auth_code code
|
68
|
+
response = get_new_tokens_using_auth_code code
|
69
|
+
dbg("renew_tokens_with_auth_code", response)
|
70
|
+
if response.code == 200
|
71
|
+
token_store.save_access_token response["access_token"]
|
72
|
+
token_store.save_refresh_token response["refresh_token"]
|
73
|
+
else
|
74
|
+
puts "Errors have occured during authentication code request:"
|
75
|
+
puts response
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def renew_tokens_with_refresh_token token
|
80
|
+
response = get_new_tokens_using_refresh_token token
|
81
|
+
dbg("renew_tokens_with_refresh_token", response)
|
82
|
+
if response.code == 200
|
83
|
+
token_store.save_access_token response["access_token"]
|
84
|
+
token_store.save_refresh_token response["refresh_token"]
|
85
|
+
else
|
86
|
+
puts "Errors have occured during token refresh request:"
|
87
|
+
puts response
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_new_tokens_using_auth_code code
|
92
|
+
url = "https://#{gamewisp_url}/pub/v1/oauth/token"
|
93
|
+
|
94
|
+
response = HTTParty.post(url,
|
95
|
+
:query => {
|
96
|
+
:grant_type => 'authorization_code',
|
97
|
+
:client_id => token_store.client_id,
|
98
|
+
:client_secret => token_store.client_secret,
|
99
|
+
:redirect_uri => redirect_uri,
|
100
|
+
:code => code,
|
101
|
+
:state => state,
|
102
|
+
})
|
103
|
+
return {:error => "#{response.code}: authorization error"} if response.code == 401
|
104
|
+
|
105
|
+
return response
|
106
|
+
end
|
107
|
+
|
108
|
+
def get_new_tokens_using_refresh_token token
|
109
|
+
url = "https://#{gamewisp_url}/pub/v1/oauth/token"
|
110
|
+
|
111
|
+
# For some reason we have to post in the :body instead of :query (as above) or we'll
|
112
|
+
# get an 'invalid refresh token' error response.
|
113
|
+
#
|
114
|
+
response = HTTParty.post(url,
|
115
|
+
:body => {
|
116
|
+
:grant_type => 'refresh_token',
|
117
|
+
:client_id => token_store.client_id,
|
118
|
+
:client_secret => token_store.client_secret,
|
119
|
+
:redirect_uri => redirect_uri,
|
120
|
+
:refresh_token => token,
|
121
|
+
})
|
122
|
+
|
123
|
+
return {:error => "#{response.code}: authorization error"} if response.code == 401
|
124
|
+
|
125
|
+
return response
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end # module
|
@@ -0,0 +1,76 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: client.rb
|
3
|
+
# Purpose:: Gamewisp API client library
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 11/07/2016
|
6
|
+
# Copyright:: Copyright (c) 2016, kTech Systems LLC. All rights reserved.
|
7
|
+
# Website:: http://ktechsystems.com
|
8
|
+
##############################################################################
|
9
|
+
|
10
|
+
require 'json/pure'
|
11
|
+
require 'httparty'
|
12
|
+
|
13
|
+
module Gamewisp
|
14
|
+
class Client
|
15
|
+
|
16
|
+
attr_accessor :token_store
|
17
|
+
attr_accessor :auth
|
18
|
+
|
19
|
+
|
20
|
+
# Only works if this class is derived (includes) HTTParty
|
21
|
+
#
|
22
|
+
#if ENV["DEBUG"]
|
23
|
+
# debug_output $stdout
|
24
|
+
#end
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
self.token_store = TokenStore.new
|
28
|
+
self.auth = Authorizer.new 'createauth', self.token_store
|
29
|
+
end
|
30
|
+
|
31
|
+
def authorize
|
32
|
+
puts "Visit the following URL in your browser and authorize #{token_store.app_name} to access your subscription metrics"
|
33
|
+
puts " #{auth.app_authorization_url}"
|
34
|
+
puts
|
35
|
+
|
36
|
+
server = auth.create_server_instance
|
37
|
+
auth_result = server.get_authentication_token
|
38
|
+
|
39
|
+
puts auth_result
|
40
|
+
if auth_result["code"]
|
41
|
+
puts "Authorization received"
|
42
|
+
else
|
43
|
+
raise GamewispError, "Authorization failed."
|
44
|
+
end
|
45
|
+
|
46
|
+
auth.renew_tokens_with_auth_code auth_result["code"]
|
47
|
+
end
|
48
|
+
|
49
|
+
def renew_access_token
|
50
|
+
if token_store.refresh_token.nil? || token_store.refresh_token.empty?
|
51
|
+
return authorize
|
52
|
+
end
|
53
|
+
|
54
|
+
auth.renew_tokens_with_refresh_token token_store.refresh_token
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_subscribers
|
58
|
+
url = "https://api.gamewisp.com/pub/v1/channel/subscribers"
|
59
|
+
|
60
|
+
dbg "Client.get_subscribers [access_token]", token_store.access_token
|
61
|
+
|
62
|
+
response = HTTParty
|
63
|
+
.get(url,
|
64
|
+
:query => {
|
65
|
+
:access_token => token_store.access_token,
|
66
|
+
:include => 'user,channel,benefits',
|
67
|
+
}
|
68
|
+
)
|
69
|
+
|
70
|
+
dbg "Client.get_subscribers [response.code]", response.code
|
71
|
+
dbg "Client.get_subscribers [response]", response
|
72
|
+
|
73
|
+
response
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end # module
|
@@ -0,0 +1,82 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: server.rb
|
3
|
+
# Purpose:: Simple server to collect authentication token
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 11/07/2016
|
6
|
+
# Copyright:: Copyright (c) 2016, kTech Systems LLC. All rights reserved.
|
7
|
+
# Website:: http://ktechsystems.com
|
8
|
+
##############################################################################
|
9
|
+
|
10
|
+
require 'socket'
|
11
|
+
|
12
|
+
module Gamewisp
|
13
|
+
class Server
|
14
|
+
|
15
|
+
attr_reader :port
|
16
|
+
attr_reader :state
|
17
|
+
|
18
|
+
def initialize port, state
|
19
|
+
@port = port
|
20
|
+
@state = state
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_authentication_token
|
24
|
+
raise ArgumentError, "No port specified" if port.nil?
|
25
|
+
raise ArgumentError, "No state specified" if state.nil?
|
26
|
+
|
27
|
+
server = TCPServer.open(port) # Socket to listen on specific port
|
28
|
+
|
29
|
+
client = server.accept
|
30
|
+
method, path = client.gets.split
|
31
|
+
headers = {}
|
32
|
+
while line = client.gets.split(" ", 2)
|
33
|
+
break if line[0] == ""
|
34
|
+
headers[line[0].chop] = line[1].strip
|
35
|
+
end
|
36
|
+
data = client.read(headers["Content-Length"].to_i)
|
37
|
+
|
38
|
+
dbg "Server:get_authentication_token [method]", method
|
39
|
+
dbg "Server:get_authentication_token [path]", path
|
40
|
+
dbg "Server:get_authentication_token [headers]", headers
|
41
|
+
dbg "Server:get_authentication_token [data]", data
|
42
|
+
|
43
|
+
results = split_path_components path
|
44
|
+
|
45
|
+
failed = false
|
46
|
+
|
47
|
+
if results["state"].nil? || results["state"] != @state
|
48
|
+
client.puts "Unrecognized request. Please try again"
|
49
|
+
failed = true
|
50
|
+
end
|
51
|
+
|
52
|
+
if results["code"].nil?
|
53
|
+
client.puts "Unrecognized request. Please try again"
|
54
|
+
failed = true
|
55
|
+
end
|
56
|
+
|
57
|
+
unless failed == true
|
58
|
+
client.puts "Authorization received. You can close this window now."
|
59
|
+
end
|
60
|
+
|
61
|
+
client.close
|
62
|
+
|
63
|
+
results
|
64
|
+
end
|
65
|
+
|
66
|
+
def split_path_components path
|
67
|
+
raise ArgumentError, "nil path returned from gamewisp" if path.nil?
|
68
|
+
|
69
|
+
vals = path.split('&', 2)
|
70
|
+
vals[0].gsub!("/?", "")
|
71
|
+
|
72
|
+
results = {}
|
73
|
+
parts = vals[0].split("=", 2)
|
74
|
+
results[parts[0]] = parts[1]
|
75
|
+
|
76
|
+
parts = vals[1].split("=", 2)
|
77
|
+
results[parts[0]] = parts[1]
|
78
|
+
|
79
|
+
results
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: token_store.rb
|
3
|
+
# Purpose:: Store Gamewisp OAuth Tokens and authenication info
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 11/07/2016
|
6
|
+
# Copyright:: Copyright (c) 2016, kTech Systems LLC. All rights reserved.
|
7
|
+
# Website:: http://ktechsystems.com
|
8
|
+
##############################################################################
|
9
|
+
|
10
|
+
module Gamewisp
|
11
|
+
class TokenStore
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@tokens = {
|
15
|
+
:access_token => '',
|
16
|
+
:refresh_token => '',
|
17
|
+
}
|
18
|
+
|
19
|
+
read_token_file
|
20
|
+
end
|
21
|
+
|
22
|
+
def client_id
|
23
|
+
ENV["GAMEWISP_ID"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def client_secret
|
27
|
+
ENV["GAMEWISP_SECRET"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def app_name
|
31
|
+
ENV["GAMEWISP_APP"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def endpoint_host
|
35
|
+
ENV["GAMEWISP_ENDPOINT_HOST"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def endpoint_port
|
39
|
+
ENV["GAMEWISP_ENDPOINT_PORT"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def save_access_token token
|
43
|
+
@tokens[:access_token] = token
|
44
|
+
write_token_file
|
45
|
+
end
|
46
|
+
|
47
|
+
def save_refresh_token token
|
48
|
+
@tokens[:refresh_token] = token
|
49
|
+
write_token_file
|
50
|
+
end
|
51
|
+
|
52
|
+
def access_token
|
53
|
+
@tokens[:access_token]
|
54
|
+
end
|
55
|
+
|
56
|
+
def refresh_token
|
57
|
+
@tokens[:refresh_token]
|
58
|
+
end
|
59
|
+
|
60
|
+
def token_file_path
|
61
|
+
filedir = "#{ENV['HOME']}/.gamewisp"
|
62
|
+
filepath = File.join(filedir, "tokens.yml")
|
63
|
+
|
64
|
+
unless File.exist?(filedir)
|
65
|
+
FileUtils.mkdir_p filedir
|
66
|
+
end
|
67
|
+
|
68
|
+
filepath
|
69
|
+
end
|
70
|
+
|
71
|
+
def write_token_file
|
72
|
+
filepath = token_file_path
|
73
|
+
|
74
|
+
File.open(filepath, 'w') do |out|
|
75
|
+
YAML.dump(@tokens, out)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def read_token_file
|
80
|
+
filepath = token_file_path
|
81
|
+
|
82
|
+
if File.exist? filepath
|
83
|
+
@tokens = YAML.load_file(filepath)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gamewisp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff McAffee
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: oauth2
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: httparty
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: json
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.0'
|
111
|
+
description: GameWisp API ruby library
|
112
|
+
email:
|
113
|
+
- jeff@ktechsystems.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
127
|
+
- gamewisp.gemspec
|
128
|
+
- lib/gamewisp.rb
|
129
|
+
- lib/gamewisp/authorizer.rb
|
130
|
+
- lib/gamewisp/client.rb
|
131
|
+
- lib/gamewisp/server.rb
|
132
|
+
- lib/gamewisp/token_store.rb
|
133
|
+
- lib/gamewisp/version.rb
|
134
|
+
homepage: https://github.com/jmcaffee/gamewisp
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.5.1
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: GameWisp API ruby library
|
158
|
+
test_files: []
|