hooktheory 0.0.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.
- checksums.yaml +7 -0
- data/lib/hooktheory.rb +6 -0
- data/lib/hooktheory/client.rb +73 -0
- data/lib/hooktheory/node.rb +11 -0
- data/lib/hooktheory/song.rb +11 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 65001c8f4305d15da2495d087b7b5b8e6f54491d
|
4
|
+
data.tar.gz: 3950e2d64353a0c232ab5f5447a8096dafc2c18a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 62465aefe9d463843dd3a4e2b1dea618883966fe1f258ee87554fadb3b5ddc1aaf869478508e5de9b80ccc970bd959c6d61b60cd5d8bb01adeefa4db82e06d96
|
7
|
+
data.tar.gz: cadbb170e62e142e9267ea529507f70c6fa83f94cd0855348bff5f5aa44c1fc14dce73a0817457b01ff9b7cb615916b36db050cc31103b93f08fb1c36453eda5
|
data/lib/hooktheory.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module HookTheory
|
4
|
+
class Client
|
5
|
+
include HTTParty
|
6
|
+
BASE_URI = "https://api.hooktheory.com/v1/"
|
7
|
+
InvalidUsernameOrPassword = Class.new(StandardError)
|
8
|
+
InvalidRequest = Class.new(StandardError)
|
9
|
+
|
10
|
+
def initialize(username:, password:)
|
11
|
+
@username = username
|
12
|
+
@password = password
|
13
|
+
@headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
|
14
|
+
grab_auth
|
15
|
+
end
|
16
|
+
|
17
|
+
def songs(progression: [], page: 1)
|
18
|
+
response = http_get(
|
19
|
+
endpoint: "trends/songs",
|
20
|
+
request_params: {
|
21
|
+
cp: progression.join(","),
|
22
|
+
page: page
|
23
|
+
})
|
24
|
+
|
25
|
+
response.map { |song| HookTheory::Song.new(song) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def nodes(progression: [])
|
29
|
+
response = http_get(
|
30
|
+
endpoint: "trends/nodes",
|
31
|
+
request_params: {
|
32
|
+
cp: progression.join(","),
|
33
|
+
})
|
34
|
+
|
35
|
+
response.map { |node| HookTheory::Node.new(node) }
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def grab_auth
|
41
|
+
auth = http_post(endpoint: "users/auth", body: {
|
42
|
+
username: @username,
|
43
|
+
password: @password
|
44
|
+
})
|
45
|
+
|
46
|
+
raise InvalidUsernameOrPassword.new("Must provide valid credentials") if auth["activkey"].nil?
|
47
|
+
@headers.merge!("Authorization" => "Bearer #{auth["activkey"]}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def http_get(endpoint:, request_params: {})
|
51
|
+
begin
|
52
|
+
self.class.get(BASE_URI + endpoint,
|
53
|
+
headers: @headers,
|
54
|
+
query: request_params
|
55
|
+
).parsed_response
|
56
|
+
rescue Exception => e
|
57
|
+
raise InvalidRequest.new(e.message)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def http_post(endpoint:, request_params: {}, body: {})
|
62
|
+
begin
|
63
|
+
self.class.post(BASE_URI + endpoint,
|
64
|
+
headers: @headers,
|
65
|
+
query: request_params,
|
66
|
+
body: body.to_json
|
67
|
+
).parsed_response
|
68
|
+
rescue Exception => e
|
69
|
+
raise InvalidRequest.new(e.message)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module HookTheory
|
2
|
+
class Node
|
3
|
+
attr_reader :chord_id, :chord_html, :probability, :child_path
|
4
|
+
def initialize(options = {})
|
5
|
+
@chord_id = options["chord_ID"]
|
6
|
+
@chord_html = options["chord_HTML"]
|
7
|
+
@probability = options["probability"]
|
8
|
+
@child_path = options["child_path"]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hooktheory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marshall Hattersley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.14'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.14.0
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.14'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.14.0
|
47
|
+
description: 'A ruby wrapper around the Hooktheory API, useful for finding information
|
48
|
+
for songs that have a particular chord progression. View the original API documentation
|
49
|
+
here: See original API documentation here: https://www.hooktheory.com/api/trends/docs'
|
50
|
+
email: mwhatters@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- lib/hooktheory.rb
|
56
|
+
- lib/hooktheory/client.rb
|
57
|
+
- lib/hooktheory/node.rb
|
58
|
+
- lib/hooktheory/song.rb
|
59
|
+
homepage: http://rubygems.org/gems/hooktheory
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 2.1.6
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.3
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Ruby client for the hooktheory API.
|
83
|
+
test_files: []
|