xbox-api 0.1.7 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8845d4286af9a4c771196a09fabc406897b4d191
4
- data.tar.gz: 0693aaff2482d2cf3cd0da1884c7a2927bd72ee9
3
+ metadata.gz: cb88cd1c60d5504c351ebf64934cfb6f3bc7abc9
4
+ data.tar.gz: 1ad23dbdb85d7674f8c758e3ba5e48f9185c7a27
5
5
  SHA512:
6
- metadata.gz: a0c866ce65d0bd5b8e7d2b1fa5d7637cf2ddb2f555ecf4444a49f15bedacb0d368307ab5d6df528977f742daa4003c4c6d9e29606d52b729a723dbdca8bc9f08
7
- data.tar.gz: 8c3047482026b14999efc35ccff3b11946ac39db67afb2e21fdfd413df86e10c2d0d6a9527b3ea658e6240ce5af4b4e40d1c1af641470e6ef6f41cfb1c9b8fb6
6
+ metadata.gz: b2704631da62ce100b505aa327f96537b20cfcb49f6860685b03eaf665456cc59cd4a29013b13dee56d46da9a6bb3228e935c6016a9cb9d5c182a5b4979e84e9
7
+ data.tar.gz: 06acec1d0108bf79d7cb56c838cc7039bd7614ac7d7aa1b025b8dbfe4487888df0a675231868425e240b08c8b921af29913ce4b46bf94c50653d7a162da0ef08
data/README.md CHANGED
@@ -13,6 +13,8 @@ This is a Ruby wrapper for the unofficial Xbox API located at http://xboxapi.com
13
13
 
14
14
  # Usage
15
15
 
16
+ ## Ruby Gem
17
+
16
18
  One must first create a client that is able to interface with the Xbox API.
17
19
  The client takes one argument; your xbox API token.
18
20
 
@@ -51,6 +53,25 @@ client = XboxApi::Client.new(ENV[:XBOX_TOKEN])
51
53
  logan = XboxApi::Gamer.new("oh hai loganz", client, "189823798746")
52
54
  ```
53
55
 
56
+ ## Commad Line
57
+
58
+ The `xbl` binary may be invoked from the command line.
59
+
60
+ `xbl -s theschoolmaster` or `xbl --status theschoolmaster` may be used to retreive the status of a given player
61
+
62
+ If you have not yet supplied your API token from XboxApi.com, you will be prompted when trying to use `xbl`
63
+
64
+ Additionally, you may clear and set you token with `xbl token`
65
+
66
+ ```sh
67
+ # clear your token
68
+ xbl token --clear
69
+
70
+ # set or view your token
71
+ xbl token
72
+ ```
73
+
74
+
54
75
  # The API
55
76
 
56
77
  ### Currently Supported Endpoints
data/bin/xbl ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/xbox-api"
4
+ require_relative "../lib/xbox-api/xboxlive"
5
+ # $thor_runner = true
6
+ XboxApi::XboxLive.start(ARGV)
@@ -1,5 +1,9 @@
1
1
  require "yajl"
2
2
  require "open-uri"
3
+ require "thor"
4
+
3
5
  require "xbox-api/version"
4
6
  require "xbox-api/client"
5
7
  require "xbox-api/gamer"
8
+ require_relative "./xbox-api/xboxlive"
9
+ # require "xbox-api/xboxlive"
@@ -1,5 +1,5 @@
1
1
  module XboxApi
2
2
  module Wrapper
3
- VERSION = "0.1.7"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1,90 @@
1
+ require 'thor'
2
+ require 'fileutils'
3
+
4
+ module XboxApi
5
+
6
+ LIVE_DIR = ".live"
7
+ TOKEN_FILE = "live-token"
8
+
9
+
10
+ class XboxLive < Thor
11
+ package_name "xbl"
12
+ map "-s" => :status
13
+
14
+ desc "status GAMERTAG","get the xbox live status of a user"
15
+ def status(gamertag)
16
+ token = TokenHelper.token_exists? ? \
17
+ TokenHelper.get_local_token : \
18
+ TokenHelper.first_run
19
+
20
+ client = Client.new(token)
21
+ puts client.gamer(gamertag).presence
22
+ end
23
+
24
+ desc "token","re/set your XboxApi token"
25
+ method_options :clear => :boolean
26
+ def token
27
+ if options.clear?
28
+
29
+ if TokenHelper.token_exists?
30
+ TokenHelper.clear!;
31
+ puts("Token deleted. Rerun `xbl token` to enter a new token")
32
+ else
33
+ puts("No token exists. Rerun `xbl token` to enter a new token")
34
+ end
35
+
36
+ else
37
+ puts TokenHelper.token_exists? ? TokenHelper.get_local_token : TokenHelper.first_run
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ module TokenHelper
44
+ extend self
45
+
46
+ def first_run
47
+ write_local_token!(get_token)
48
+ puts "Token saved!"
49
+ end
50
+
51
+ def clear!
52
+ if token_exists?
53
+ FileUtils.rm token_file
54
+ end
55
+ end
56
+
57
+ def write_local_token!(token)
58
+ create_token_dir! unless Dir.exists? token_path
59
+ File.write(token_file, token)
60
+ token
61
+ end
62
+
63
+ def create_token_dir!
64
+ Dir.mkdir(token_path)
65
+ end
66
+
67
+ def token_exists?
68
+ File.exists?(token_file)
69
+ end
70
+
71
+ def get_local_token
72
+ raise "No Token Found at #{token_path}" unless token_exists?
73
+ File.read(token_file).chomp
74
+ end
75
+
76
+ def token_path
77
+ File.join(Dir.home, XboxApi::LIVE_DIR)
78
+ end
79
+
80
+ def token_file
81
+ File.join(token_path, XboxApi::TOKEN_FILE)
82
+ end
83
+
84
+ def get_token
85
+ print 'XboxAPI Token: '
86
+ username = $stdin.gets.chomp
87
+ end
88
+
89
+ end
90
+ end
@@ -145,4 +145,36 @@ let(:gamer) { VCR.use_cassette("gamer") { client.gamer("audibleblink") } }
145
145
  end
146
146
  end
147
147
 
148
+ describe XboxApi::XboxLive do
149
+ context "#status" do
150
+ xit "displays an status for a valid user" do
151
+ VCR.use_cassette("thor-status-valid") do
152
+ expect{system("xbl -s theschoolmaster")}.to output("").to_stdout
153
+ end
154
+ end
155
+
156
+ xit "prompts for token when none is present" do
157
+ XboxApi::TokenHelper.clear!
158
+ expect{system("xbl -s theschoolmaster")}.to output("XboxAPI Token:").to_stdout
159
+ end
160
+ end
161
+
162
+ context "#token" do
163
+ let(:token){"123123"}
164
+
165
+ it "displays a token" do
166
+ XboxApi::TokenHelper.write_local_token!(token)
167
+ output = `xbl token`.chomp
168
+ expect(output).to eq token
169
+ end
170
+
171
+ it "clears a token" do
172
+ XboxApi::TokenHelper.write_local_token!(token)
173
+ warning = `xbl token --clear`.chomp
174
+ expect(warning).to eq("Token deleted. Rerun `xbl token` to enter a new token")
175
+ end
176
+ end
177
+
178
+ end
179
+
148
180
  end
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = XboxApi::Wrapper::VERSION
17
17
 
18
+ gem.add_runtime_dependency("thor")
18
19
  gem.add_runtime_dependency("yajl-ruby")
19
20
  gem.add_development_dependency("rspec")
20
21
  gem.add_development_dependency("vcr")
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xbox-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Flores
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: yajl-ruby
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +112,8 @@ description: An Xbox API wrapper that allows one to fetch profiles, games, achie
98
112
  and friends data
99
113
  email:
100
114
  - xboxapin@alexflor.es
101
- executables: []
115
+ executables:
116
+ - xbl
102
117
  extensions: []
103
118
  extra_rdoc_files: []
104
119
  files:
@@ -108,10 +123,12 @@ files:
108
123
  - LICENSE
109
124
  - README.md
110
125
  - Rakefile
126
+ - bin/xbl
111
127
  - lib/xbox-api.rb
112
128
  - lib/xbox-api/client.rb
113
129
  - lib/xbox-api/gamer.rb
114
130
  - lib/xbox-api/version.rb
131
+ - lib/xbox-api/xboxlive.rb
115
132
  - spec/spec_helper.rb
116
133
  - spec/support/console.rb
117
134
  - spec/vcr/activity.yml