genius 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +56 -0
- data/.rubocop_todo.yml +117 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +7 -0
- data/README.md +7 -1
- data/Rakefile +1 -1
- data/genius.gemspec +1 -0
- data/lib/genius/account.rb +4 -3
- data/lib/genius/annotation.rb +39 -0
- data/lib/genius/errors.rb +5 -4
- data/lib/genius/referent.rb +1 -1
- data/lib/genius/resource.rb +23 -6
- data/lib/genius/version.rb +1 -1
- data/lib/genius/web_page.rb +5 -3
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c727308708c8f45cbb85934762b28cdb8f3c6c5a
|
4
|
+
data.tar.gz: b9b7651fd5ddd04fd300a57a825d9c03eeaad0c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4669440fe4adf3bd25692f09063bbff7b7ca62b9308d86c1578a503a68ccb38a50b9c4ff4510099abdfedd0cbe91beb51d073212a83a4c81d1b9ab675c47f8d
|
7
|
+
data.tar.gz: e372cebf483d5d86f033a611a8f3446c293441c8fbf17b0710e6d38f6bbb29f0e57195176ba8ca662019d88283bf907bf7d7a42cf450fd66b8fc684fb7c9ecbe
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# For all options see https://github.com/bbatsov/rubocop/tree/master/config
|
2
|
+
|
3
|
+
inherit_from: .rubocop_todo.yml
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
RunRailsCops: false
|
7
|
+
Include:
|
8
|
+
- Rakefile
|
9
|
+
Exclude:
|
10
|
+
- .*/**/*
|
11
|
+
|
12
|
+
# Limit lines to 80 characters.
|
13
|
+
LineLength:
|
14
|
+
Max: 90
|
15
|
+
|
16
|
+
ClassLength:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
ModuleLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
# Avoid methods longer than 30 lines of code
|
23
|
+
MethodLength:
|
24
|
+
CountComments: false # count full line comments?
|
25
|
+
Max: 87
|
26
|
+
|
27
|
+
# Avoid single-line methods.
|
28
|
+
SingleLineMethods:
|
29
|
+
AllowIfMethodIsEmpty: true
|
30
|
+
|
31
|
+
StringLiterals:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
GlobalVars:
|
35
|
+
Enabled: false # We use them Redis + StatsD (though maybe we shouldn't?)
|
36
|
+
|
37
|
+
# Wants underscores in all large numbers. Pain in the ass for things like
|
38
|
+
# unix timestamps.
|
39
|
+
NumericLiterals:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
# Wants you to use the same argument names for every reduce. This seems kinda
|
43
|
+
# naff compared to naming them semantically
|
44
|
+
SingleLineBlockParams:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Style/SignalException:
|
48
|
+
EnforcedStyle: 'only_raise'
|
49
|
+
|
50
|
+
# Use trailing rather than leading dots on multi-line call chains
|
51
|
+
Style/DotPosition:
|
52
|
+
EnforcedStyle: trailing
|
53
|
+
|
54
|
+
# Allow non-ASCII characters (e.g. £) in comments
|
55
|
+
Style/AsciiComments:
|
56
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-06-06 22:47:07 +0100 using RuboCop version 0.32.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 50
|
9
|
+
# Cop supports --auto-correct.
|
10
|
+
Lint/UnusedBlockArgument:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
# Offense count: 187
|
14
|
+
Metrics/AbcSize:
|
15
|
+
Max: 61
|
16
|
+
|
17
|
+
# Offense count: 26
|
18
|
+
Metrics/CyclomaticComplexity:
|
19
|
+
Max: 10
|
20
|
+
|
21
|
+
# Offense count: 11
|
22
|
+
Metrics/PerceivedComplexity:
|
23
|
+
Max: 10
|
24
|
+
|
25
|
+
# Offense count: 12
|
26
|
+
Style/AccessorMethodName:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
# Offense count: 164
|
30
|
+
# Cop supports --auto-correct.
|
31
|
+
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
|
32
|
+
Style/AlignHash:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
# Offense count: 3
|
36
|
+
# Cop supports --auto-correct.
|
37
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
38
|
+
Style/BlockDelimiters:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
# Offense count: 128
|
42
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
43
|
+
Style/ClassAndModuleChildren:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
# Offense count: 21
|
47
|
+
# Cop supports --auto-correct.
|
48
|
+
Style/ClosingParenthesisIndentation:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
# Offense count: 13
|
52
|
+
# Cop supports --auto-correct.
|
53
|
+
# Configuration parameters: Keywords.
|
54
|
+
Style/CommentAnnotation:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
# Offense count: 743
|
58
|
+
Style/Documentation:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
# Offense count: 9
|
62
|
+
Style/DoubleNegation:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
# Offense count: 109
|
66
|
+
# Configuration parameters: MinBodyLength.
|
67
|
+
Style/GuardClause:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
# Offense count: 48
|
71
|
+
# Cop supports --auto-correct.
|
72
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
73
|
+
Style/IndentHash:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
# Offense count: 70
|
77
|
+
# Cop supports --auto-correct.
|
78
|
+
Style/Lambda:
|
79
|
+
Enabled: false
|
80
|
+
|
81
|
+
# Offense count: 577
|
82
|
+
# Cop supports --auto-correct.
|
83
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
84
|
+
Style/MultilineOperationIndentation:
|
85
|
+
Enabled: false
|
86
|
+
|
87
|
+
# Offense count: 21
|
88
|
+
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
|
89
|
+
Style/PredicateName:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
# Offense count: 4
|
93
|
+
# Cop supports --auto-correct.
|
94
|
+
Style/Proc:
|
95
|
+
Enabled: false
|
96
|
+
|
97
|
+
# Offense count: 173
|
98
|
+
# Cop supports --auto-correct.
|
99
|
+
Style/RedundantSelf:
|
100
|
+
Enabled: false
|
101
|
+
|
102
|
+
# Offense count: 28
|
103
|
+
# Cop supports --auto-correct.
|
104
|
+
Style/SingleSpaceBeforeFirstArg:
|
105
|
+
Enabled: false
|
106
|
+
|
107
|
+
# Offense count: 3
|
108
|
+
# Cop supports --auto-correct.
|
109
|
+
# Configuration parameters: MultiSpaceAllowedForOperators.
|
110
|
+
Style/SpaceAroundOperators:
|
111
|
+
Enabled: false
|
112
|
+
|
113
|
+
# Offense count: 5
|
114
|
+
# Cop supports --auto-correct.
|
115
|
+
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
|
116
|
+
Style/TrivialAccessors:
|
117
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Genius
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/timrogers/genius.svg)](https://travis-ci.org/timrogers/genius)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/genius.svg)](http://badge.fury.io/rb/genius)
|
5
|
+
|
3
6
|
![Genius logo](http://assets.rapgenius.com/images/apple-touch-icon.png?1432674944)
|
4
7
|
|
5
8
|
## What does this do?
|
@@ -129,13 +132,16 @@ me.iq
|
|
129
132
|
|
130
133
|
Check out [account.rb](https://github.com/timrogers/genius/blob/master/lib/genius/account.rb) or the [Genius API documentation](https://docs.genius.com/#account-h2) for a full list of available fields.
|
131
134
|
|
135
|
+
### Other resources
|
136
|
+
|
137
|
+
The API library also supports working with web pages, annotations and referents in the API. See the [Genius API documentation](https://docs.genius.com/#account-h2) and the library [source](https://github.com/timrogers/genius/tree/master/lib/genius).
|
132
138
|
|
133
139
|
## Contributing
|
134
140
|
|
135
141
|
If you'd like to contribute anything else, go ahead or better still, make an issue and we can talk it over and spec it out! A few quick tips:
|
136
142
|
|
137
143
|
* Don't update the version numbers before your pull request - I'll sort that part out for you.
|
138
|
-
* Make sure you write specs, then run them with `$ bundle exec rake`
|
144
|
+
* Make sure you write specs, then run them with `$ bundle exec rake`. When running tests, you'll want to set `GENIUS_ACCESS_TOKEN` so your requests can be authenticated - don't worry, your token will be filtered out of the `vcr` cassettes.
|
139
145
|
* Update this README.md file so I, and users, know how your changes work
|
140
146
|
|
141
147
|
## Copyright
|
data/Rakefile
CHANGED
data/genius.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "mocha", "~> 0.14.0"
|
27
27
|
spec.add_development_dependency "webmock", "~> 1.11.0"
|
28
28
|
spec.add_development_dependency "vcr", "~> 2.5.0"
|
29
|
+
spec.add_development_dependency "rubocop", "~> 0.31.0"
|
29
30
|
|
30
31
|
spec.add_runtime_dependency "httparty", "~> 0.11.0"
|
31
32
|
end
|
data/lib/genius/account.rb
CHANGED
@@ -26,7 +26,7 @@ module Genius
|
|
26
26
|
raise NotReloadableError, "An Account cannot be reloaded"
|
27
27
|
end
|
28
28
|
|
29
|
-
def self.find(
|
29
|
+
def self.find(*)
|
30
30
|
raise NotImplementedError, "An Account cannot be loaded by its ID in the public API"
|
31
31
|
end
|
32
32
|
|
@@ -34,8 +34,9 @@ module Genius
|
|
34
34
|
headers = default_headers.merge(params.delete(:headers) || {})
|
35
35
|
params = default_params.merge(params)
|
36
36
|
|
37
|
-
new(http_get("/account", query: params,
|
38
|
-
|
37
|
+
new(http_get("/account", query: params,
|
38
|
+
headers: headers),
|
39
|
+
text_format: params[:text_format])
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
data/lib/genius/annotation.rb
CHANGED
@@ -15,5 +15,44 @@ module Genius
|
|
15
15
|
@id = resource["id"]
|
16
16
|
@url = resource["url"]
|
17
17
|
end
|
18
|
+
|
19
|
+
def update!(body = {})
|
20
|
+
response = self.class.http_put("/annotations/#{id}",
|
21
|
+
body: body,
|
22
|
+
headers: self.class.default_headers)
|
23
|
+
|
24
|
+
self.class.new(response, text_format: text_format)
|
25
|
+
end
|
26
|
+
|
27
|
+
def destroy!
|
28
|
+
self.class.http_delete("/annotations/#{id}", headers: self.class.default_headers)
|
29
|
+
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def upvote!
|
34
|
+
self.class.http_put("/annotations/#{id}/upvote",
|
35
|
+
headers: self.class.default_headers)
|
36
|
+
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def unvote!
|
41
|
+
self.class.http_put("/annotations/#{id}/unvote",
|
42
|
+
headers: self.class.default_headers)
|
43
|
+
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
def downvote!
|
48
|
+
self.class.http_put("/annotations/#{id}/downvote",
|
49
|
+
headers: self.class.default_headers)
|
50
|
+
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.create!(body = {})
|
55
|
+
new(http_post("/annotations", body: body, headers: default_headers))
|
56
|
+
end
|
18
57
|
end
|
19
58
|
end
|
data/lib/genius/errors.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Genius
|
2
|
-
class
|
3
|
-
class
|
4
|
-
class
|
5
|
-
class
|
2
|
+
class Error < StandardError; end
|
3
|
+
class NotFoundError < Error; end
|
4
|
+
class AuthenticationError < Error; end
|
5
|
+
class MissingAccessTokenError < Error; end
|
6
|
+
class NotReloadableError < Error; end
|
6
7
|
end
|
data/lib/genius/referent.rb
CHANGED
@@ -3,7 +3,7 @@ module Genius
|
|
3
3
|
attr_reader :id, :url, :song_id, :annotator_id, :fragment, :range, :classification,
|
4
4
|
:annotatable, :annotations
|
5
5
|
|
6
|
-
def self.find(
|
6
|
+
def self.find(*)
|
7
7
|
raise NotImplementedError, "A Referent cannot be loaded by its ID in the public API"
|
8
8
|
end
|
9
9
|
|
data/lib/genius/resource.rb
CHANGED
@@ -10,10 +10,7 @@ module Genius
|
|
10
10
|
attr_reader :raw_response, :resource
|
11
11
|
|
12
12
|
def self.resource_name(resource_name = nil)
|
13
|
-
if resource_name
|
14
|
-
@resource_name = resource_name
|
15
|
-
end
|
16
|
-
|
13
|
+
@resource_name = resource_name if resource_name
|
17
14
|
@resource_name || name.downcase.split("::").last
|
18
15
|
end
|
19
16
|
|
@@ -21,8 +18,10 @@ module Genius
|
|
21
18
|
params = default_params.merge(params)
|
22
19
|
headers = default_headers.merge(headers)
|
23
20
|
|
24
|
-
new(http_get("/#{resource_name}s/#{id}",
|
25
|
-
|
21
|
+
new(http_get("/#{resource_name}s/#{id}",
|
22
|
+
query: params,
|
23
|
+
headers: headers),
|
24
|
+
text_format: params[:text_format])
|
26
25
|
end
|
27
26
|
|
28
27
|
def reload
|
@@ -31,7 +30,25 @@ module Genius
|
|
31
30
|
|
32
31
|
def self.http_get(path, query: {}, headers: {})
|
33
32
|
response = get(path, query: query, headers: headers)
|
33
|
+
handle_response(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.http_post(path, body: {}, headers: {})
|
37
|
+
response = post(path, body: body, headers: headers)
|
38
|
+
handle_response(response)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.http_put(path, body: {}, headers: {})
|
42
|
+
response = put(path, body: body, headers: headers)
|
43
|
+
handle_response(response)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.http_delete(path, headers: {})
|
47
|
+
response = delete(path, headers: headers)
|
48
|
+
handle_response(response)
|
49
|
+
end
|
34
50
|
|
51
|
+
def self.handle_response(response)
|
35
52
|
case response.code
|
36
53
|
when 404 then raise NotFoundError
|
37
54
|
when 401, 403 then raise AuthenticationError
|
data/lib/genius/version.rb
CHANGED
data/lib/genius/web_page.rb
CHANGED
@@ -14,7 +14,7 @@ module Genius
|
|
14
14
|
@annotation_count = resource["annotation_count"]
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.find(
|
17
|
+
def self.find(*)
|
18
18
|
raise NotImplementedError, "A Web Page cannot be loaded by its ID in the public API"
|
19
19
|
end
|
20
20
|
|
@@ -26,8 +26,10 @@ module Genius
|
|
26
26
|
headers = default_headers.merge(params.delete(:headers) || {})
|
27
27
|
params = default_params.merge(params)
|
28
28
|
|
29
|
-
new(http_get("/#{resource_name}s/lookup",
|
30
|
-
|
29
|
+
new(http_get("/#{resource_name}s/lookup",
|
30
|
+
query: params,
|
31
|
+
headers: headers),
|
32
|
+
text_format: params[:text_format])
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: genius
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Rogers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 2.5.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.31.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.31.0
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: httparty
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,7 +145,10 @@ extra_rdoc_files: []
|
|
131
145
|
files:
|
132
146
|
- ".gitignore"
|
133
147
|
- ".rspec"
|
148
|
+
- ".rubocop.yml"
|
149
|
+
- ".rubocop_todo.yml"
|
134
150
|
- ".travis.yml"
|
151
|
+
- CHANGELOG.md
|
135
152
|
- CODE_OF_CONDUCT.md
|
136
153
|
- Gemfile
|
137
154
|
- LICENSE.txt
|