genius 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 99591718ba879a8d777a77d36774ba38902a5fc2
4
- data.tar.gz: 611a7e528d428f6ff2d539f5163a9f7481aa7d11
2
+ SHA256:
3
+ metadata.gz: 4729bfa0e842e8bbddbc1ef480ad8629fafcfda599d161d24035aff1ea943f3f
4
+ data.tar.gz: acb528fb6f79cb0999b3b7403266da3261473b40152a707b2e44cdd37aa5e296
5
5
  SHA512:
6
- metadata.gz: bb7182b7640f26ed6b7cde30fd3004968ce89ee4374b1355c5ca6aadfb5cca3f94f7e620928bb1885ee006b4978263087f84d0cbb8c8d46f9dd72170c9f1485a
7
- data.tar.gz: 71f6e64bd982c826384c99a07ad5dbff0263ae3052ed8d145532001363baf99d5fc0f0531e44a15bbef9bd72f185aec5dfa2b4f5e0d8a3fcdcb836d6ddccd6e7
6
+ metadata.gz: f081bf36c8fa1d8ce3246eb99aa775bd7da0a63a9566d5bddfa983d4f8309bb42ad126b3515e06d0957796c1789fc0e09598bfef437a0d36ff59258ba83afc73
7
+ data.tar.gz: 0052b27d674249428000ff9212ef9f8a568e128cd5ca44d53a53b69b01aefd7796e786416bcc6ffedc34fccdbc5c0299999a698e5cce70c7462a1f0d79f347a5
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
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
@@ -1,4 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.0
4
+ - 2.0.0
4
5
  before_install: gem install bundler -v 1.10.4
6
+ script:
7
+ - bundle exec rubocop
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## 0.1.2 (18th January 2023)
2
+
3
+ * Update `httparty` to v0.21.0 (@kkbaranski)
4
+
5
+ ## 0.1.1 (3rd July 2015)
6
+
7
+ * Support for new Annotations APIs
8
+
9
+ ## 0.1.0 (26th June 2015)
10
+
11
+ * Initial release
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?
@@ -12,7 +15,7 @@ It's a Ruby gem for accessing songs, artists and annotations on
12
15
  Install the gem, and you're ready to go. Simply add the following to your Gemfile:
13
16
 
14
17
  ```ruby
15
- gem "genius", "~> 0.1.0"
18
+ gem "genius", "~> 0.1.2"
16
19
  ```
17
20
 
18
21
  ## Usage
@@ -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
@@ -3,4 +3,4 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/genius.gemspec CHANGED
@@ -19,13 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.10"
23
22
  spec.add_development_dependency "rake", "~> 10.0"
24
23
  spec.add_development_dependency "rspec", "~> 3.3.0"
25
24
  spec.add_development_dependency "rspec-its", "~> 1.1.0"
26
25
  spec.add_development_dependency "mocha", "~> 0.14.0"
27
26
  spec.add_development_dependency "webmock", "~> 1.11.0"
28
27
  spec.add_development_dependency "vcr", "~> 2.5.0"
28
+ spec.add_development_dependency "rubocop", "~> 0.31.0"
29
29
 
30
- spec.add_runtime_dependency "httparty", "~> 0.11.0"
30
+ spec.add_runtime_dependency "httparty", "~> 0.21.0"
31
31
  end
@@ -26,7 +26,7 @@ module Genius
26
26
  raise NotReloadableError, "An Account cannot be reloaded"
27
27
  end
28
28
 
29
- def self.find(id, params: {}, headers: {})
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, headers: headers),
38
- text_format: params[:text_format])
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
@@ -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 NotFoundError < StandardError; end
3
- class AuthenticationError < StandardError; end
4
- class MissingAccessTokenError < StandardError; end
5
- class NotReloadableError < StandardError; end
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
@@ -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(id, params: {}, headers: {})
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
 
@@ -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}", query: params, headers: headers),
25
- text_format: params[:text_format])
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
@@ -1,3 +1,3 @@
1
1
  module Genius
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -14,7 +14,7 @@ module Genius
14
14
  @annotation_count = resource["annotation_count"]
15
15
  end
16
16
 
17
- def self.find(id, params: {}, headers: {})
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", query: params, headers: headers),
30
- text_format: params[:text_format])
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,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genius
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Rogers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-26 00:00:00.000000000 Z
11
+ date: 2023-01-18 00:00:00.000000000 Z
12
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.10'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.10'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -108,20 +94,34 @@ dependencies:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
96
  version: 2.5.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.31.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.31.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: httparty
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.11.0
117
+ version: 0.21.0
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.11.0
124
+ version: 0.21.0
125
125
  description: A Ruby client for the Genius API (<http://genius.com/developers>).
126
126
  email:
127
127
  - tim@gocardless.com
@@ -131,7 +131,10 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
133
  - ".rspec"
134
+ - ".rubocop.yml"
135
+ - ".rubocop_todo.yml"
134
136
  - ".travis.yml"
137
+ - CHANGELOG.md
135
138
  - CODE_OF_CONDUCT.md
136
139
  - Gemfile
137
140
  - LICENSE.txt
@@ -154,7 +157,7 @@ homepage: https://github.com/timrogers/genius
154
157
  licenses:
155
158
  - MIT
156
159
  metadata: {}
157
- post_install_message:
160
+ post_install_message:
158
161
  rdoc_options: []
159
162
  require_paths:
160
163
  - lib
@@ -169,9 +172,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
172
  - !ruby/object:Gem::Version
170
173
  version: '0'
171
174
  requirements: []
172
- rubyforge_project:
173
- rubygems_version: 2.4.7
174
- signing_key:
175
+ rubygems_version: 3.4.1
176
+ signing_key:
175
177
  specification_version: 4
176
178
  summary: A Ruby client for the Genius API (<http://genius.com/developers>).
177
179
  test_files: []