beats-client 0.2.0 → 0.2.1
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.
- data/.gitignore +2 -0
- data/.rvmrc +1 -1
- data/.yardopts +2 -0
- data/HISTORY.md +8 -0
- data/README.md +57 -2
- data/beats-client.gemspec +3 -0
- data/lib/beats/auth.rb +12 -0
- data/lib/beats/client.rb +19 -0
- data/lib/beats/commands/base.rb +5 -0
- data/lib/beats/version.rb +1 -1
- metadata +88 -82
data/.gitignore
CHANGED
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm 1.
|
1
|
+
rvm 1.9.2@beats-ruby-client --create
|
data/.yardopts
ADDED
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,58 @@
|
|
1
|
-
|
1
|
+
Beats Client
|
2
|
+
============
|
2
3
|
|
3
|
-
A CLI client and SDK for Beats API.
|
4
|
+
A CLI client and SDK for the Beats API.
|
5
|
+
|
6
|
+
Setup
|
7
|
+
-----
|
8
|
+
|
9
|
+
Both the command line client and the SDK is packaged as a Ruby gem called
|
10
|
+
"beats-client". It's available from rubygems.org, so simply install it with
|
11
|
+
the gem command or using bundler:
|
12
|
+
|
13
|
+
$ gem install beats-client
|
14
|
+
|
15
|
+
Example usage
|
16
|
+
-------------
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require 'beats-client'
|
20
|
+
|
21
|
+
# Create a client object
|
22
|
+
client = Beats::Client.new
|
23
|
+
|
24
|
+
# Create an authenticated client object
|
25
|
+
client = Beats::Client.new(:access_token => '...')
|
26
|
+
|
27
|
+
client.account # => { ... }
|
28
|
+
client.resource('Arthur-Russell') # => { "uri" => "Arthur-Russell", "name" => "Arthur Russell", "type" => "Artist", ... }
|
29
|
+
client.search('death metal') # => { "tracks" => [...], ... }
|
30
|
+
```
|
31
|
+
|
32
|
+
Development
|
33
|
+
-----------
|
34
|
+
|
35
|
+
If you want to make your own changes to beats-client, first clone the repo and
|
36
|
+
run the tests:
|
37
|
+
|
38
|
+
git clone git://github.com/ProjectDaisy/beats-ruby-client.git
|
39
|
+
cd beats-ruby-client
|
40
|
+
bundle install
|
41
|
+
rake test
|
42
|
+
|
43
|
+
Contributing
|
44
|
+
------------
|
45
|
+
|
46
|
+
Once you've made your great commits:
|
47
|
+
|
48
|
+
1. Fork the repo
|
49
|
+
2. Create a topic branch - git checkout -b my_branch
|
50
|
+
3. Push to your branch - git push origin my_branch
|
51
|
+
4. Create a Pull Request from your branch
|
52
|
+
5. That's it!
|
53
|
+
|
54
|
+
Author
|
55
|
+
------
|
56
|
+
|
57
|
+
Copyright ©2012 Beats Music Europe AB.
|
58
|
+
Created by Niklas Holmgren (niklas@sutajio.se).
|
data/beats-client.gemspec
CHANGED
@@ -20,4 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_dependency 'multi_json'
|
21
21
|
s.add_dependency 'json_pure'
|
22
22
|
s.add_development_dependency 'rake'
|
23
|
+
s.add_development_dependency 'yard'
|
24
|
+
s.add_development_dependency 'redcarpet'
|
25
|
+
s.add_development_dependency 'github-markup'
|
23
26
|
end
|
data/lib/beats/auth.rb
CHANGED
@@ -1,15 +1,27 @@
|
|
1
1
|
module Beats
|
2
|
+
# Helper class for asking for and handling authentication credentials. The
|
3
|
+
# CLI interface uses this class to prompt the user for her credentials when
|
4
|
+
# she tries to access a protected resource.
|
5
|
+
# @note Credentials are stored in a users home directiory in the file
|
6
|
+
# ~/.beats/credentials.yml.
|
2
7
|
class Auth
|
3
8
|
class << self
|
4
9
|
|
10
|
+
# Prompt the user for her credentials. Will display an interactive
|
11
|
+
# command line prompt. If the credentials are valid they will be cached
|
12
|
+
# in the ~/.beats/credentials.yml file (as an access token).
|
5
13
|
def login
|
6
14
|
ask_for_credentials
|
7
15
|
end
|
8
16
|
|
17
|
+
# Wipe the current users credentials from the system.
|
9
18
|
def logout
|
10
19
|
delete_credentials
|
11
20
|
end
|
12
21
|
|
22
|
+
# Reads the users access token from her credentials file.
|
23
|
+
# @return [String] An access token, or nil if the user hasn't
|
24
|
+
# authenticated yet.
|
13
25
|
def access_token
|
14
26
|
@credentials ||= read_credentials
|
15
27
|
if @credentials
|
data/lib/beats/client.rb
CHANGED
@@ -24,30 +24,49 @@ module Beats
|
|
24
24
|
@access_token = options[:access_token]
|
25
25
|
end
|
26
26
|
|
27
|
+
# Retrieves the resource discovery index. The index is a set of links
|
28
|
+
# to other resources.
|
29
|
+
# @return [Hash] A hash with a "links" field (an array of hashes
|
30
|
+
# representing the links).
|
27
31
|
def index
|
28
32
|
get(@base_url)
|
29
33
|
rescue RestClient::MultipleChoices => e
|
30
34
|
@index ||= decode_json(e.response.body)
|
31
35
|
end
|
32
36
|
|
37
|
+
# Retrieves the representation of the currently authenticated user.
|
38
|
+
# Requires authentication.
|
39
|
+
# @return [Hash] A hash with info about the current user.
|
33
40
|
def account
|
34
41
|
decode_json(get(resolve_uri(@base_url, href(:account))))
|
35
42
|
end
|
36
43
|
|
44
|
+
# Retrieves the representation of a resource.
|
45
|
+
# @param [String] uri A relative or absolute URI that names the resource.
|
46
|
+
# @return [Hash] A hash with at least the fields "uri", "name" and "type".
|
37
47
|
def resource(uri)
|
38
48
|
decode_json(get(resolve_uri(@base_url, uri)))
|
39
49
|
end
|
40
50
|
|
51
|
+
# Performs a search in the music catalogue and returns the results.
|
52
|
+
# @param [String] query A search query, like "the beatles".
|
53
|
+
# @return [Hash] A hash with array fields for the different kinds of
|
54
|
+
# resource types found.
|
41
55
|
def search(query)
|
42
56
|
decode_json(get(resolve_uri(@base_url, href(:search)),
|
43
57
|
:params => { :q => query }))
|
44
58
|
end
|
45
59
|
|
60
|
+
# Adds a resource (e.g. a track) to the currently authenticated users
|
61
|
+
# history. Requires authentication.
|
62
|
+
# @param [String] uri The *relative* URI for a resource (usually a track).
|
46
63
|
def add_history(uri)
|
47
64
|
post(resolve_uri(@base_url, href(:history)),
|
48
65
|
:uri => uri)
|
49
66
|
end
|
50
67
|
|
68
|
+
# Retrieves the building blocks for "The Sentence".
|
69
|
+
# @return [Hash] The bulding blocks for the sentence.
|
51
70
|
def sentence
|
52
71
|
decode_json(get(resolve_uri(@base_url, href(:sentence))))
|
53
72
|
end
|
data/lib/beats/commands/base.rb
CHANGED
@@ -3,6 +3,11 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
module Beats
|
5
5
|
module Command
|
6
|
+
# @abstract
|
7
|
+
# Beats::Command::Base is the base class for all commands.
|
8
|
+
# subclass it and add public methods that will become commands. Methods
|
9
|
+
# named like the subclass will become the default command for that
|
10
|
+
# command group.
|
6
11
|
class Base
|
7
12
|
|
8
13
|
attr_reader :args
|
data/lib/beats/version.rb
CHANGED
metadata
CHANGED
@@ -1,90 +1,104 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: beats-client
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Niklas Holmgren
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-02-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: rest-client
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70303674723960 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: multi_json
|
36
23
|
prerelease: false
|
37
|
-
|
24
|
+
version_requirements: *70303674723960
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: multi_json
|
27
|
+
requirement: &70303674723540 !ruby/object:Gem::Requirement
|
38
28
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
46
33
|
type: :runtime
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: json_pure
|
50
34
|
prerelease: false
|
51
|
-
|
35
|
+
version_requirements: *70303674723540
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: json_pure
|
38
|
+
requirement: &70303674723120 !ruby/object:Gem::Requirement
|
52
39
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
version: "0"
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
60
44
|
type: :runtime
|
61
|
-
|
62
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70303674723120
|
47
|
+
- !ruby/object:Gem::Dependency
|
63
48
|
name: rake
|
49
|
+
requirement: &70303674722700 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
64
56
|
prerelease: false
|
65
|
-
|
57
|
+
version_requirements: *70303674722700
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: yard
|
60
|
+
requirement: &70303674722280 !ruby/object:Gem::Requirement
|
66
61
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
segments:
|
72
|
-
- 0
|
73
|
-
version: "0"
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
74
66
|
type: :development
|
75
|
-
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70303674722280
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redcarpet
|
71
|
+
requirement: &70303674721860 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70303674721860
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: github-markup
|
82
|
+
requirement: &70303674721440 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70303674721440
|
76
91
|
description: A CLI client and SDK for Beats API
|
77
|
-
email:
|
92
|
+
email:
|
78
93
|
- niklas@sutajio.se
|
79
|
-
executables:
|
94
|
+
executables:
|
80
95
|
- beats
|
81
96
|
extensions: []
|
82
|
-
|
83
97
|
extra_rdoc_files: []
|
84
|
-
|
85
|
-
files:
|
98
|
+
files:
|
86
99
|
- .gitignore
|
87
100
|
- .rvmrc
|
101
|
+
- .yardopts
|
88
102
|
- Gemfile
|
89
103
|
- HISTORY.md
|
90
104
|
- README.md
|
@@ -108,38 +122,30 @@ files:
|
|
108
122
|
- test/test_helper.rb
|
109
123
|
homepage: https://github.com/ProjectDaisy/beats-ruby-client
|
110
124
|
licenses: []
|
111
|
-
|
112
125
|
post_install_message:
|
113
126
|
rdoc_options: []
|
114
|
-
|
115
|
-
require_paths:
|
127
|
+
require_paths:
|
116
128
|
- lib
|
117
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
130
|
none: false
|
119
|
-
requirements:
|
120
|
-
- -
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
|
123
|
-
|
124
|
-
- 0
|
125
|
-
version: "0"
|
126
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
136
|
none: false
|
128
|
-
requirements:
|
129
|
-
- -
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
|
132
|
-
segments:
|
133
|
-
- 0
|
134
|
-
version: "0"
|
137
|
+
requirements:
|
138
|
+
- - ! '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
135
141
|
requirements: []
|
136
|
-
|
137
142
|
rubyforge_project:
|
138
|
-
rubygems_version: 1.8.
|
143
|
+
rubygems_version: 1.8.15
|
139
144
|
signing_key:
|
140
145
|
specification_version: 3
|
141
146
|
summary: A CLI client and SDK for Beats API
|
142
|
-
test_files:
|
147
|
+
test_files:
|
143
148
|
- test/client_test.rb
|
144
149
|
- test/command_test.rb
|
145
150
|
- test/test_helper.rb
|
151
|
+
has_rdoc:
|