hypem 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.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +95 -0
- data/Rakefile +7 -0
- data/fixtures/vcr_cassettes/blog_playlist.yml +156 -0
- data/fixtures/vcr_cassettes/feed_playlist.yml +150 -0
- data/fixtures/vcr_cassettes/fresh_playlist.yml +230 -0
- data/fixtures/vcr_cassettes/friends_history.yml +144 -0
- data/fixtures/vcr_cassettes/friends_playlist.yml +150 -0
- data/fixtures/vcr_cassettes/latest_playlist.yml +226 -0
- data/fixtures/vcr_cassettes/loved_playlist.yml +146 -0
- data/fixtures/vcr_cassettes/obsessed_playlist.yml +151 -0
- data/fixtures/vcr_cassettes/popular_playlist.yml +167 -0
- data/fixtures/vcr_cassettes/user_profile.yml +44 -0
- data/hypem.gemspec +27 -0
- data/lib/hypem.rb +21 -0
- data/lib/hypem/playlist.rb +56 -0
- data/lib/hypem/request.rb +28 -0
- data/lib/hypem/response.rb +14 -0
- data/lib/hypem/track.rb +35 -0
- data/lib/hypem/user.rb +49 -0
- data/lib/hypem/version.rb +3 -0
- data/spec/hypem_spec.rb +13 -0
- data/spec/playlist_spec.rb +132 -0
- data/spec/request_spec.rb +33 -0
- data/spec/response_spec.rb +22 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/track_spec.rb +16 -0
- data/spec/user_spec.rb +62 -0
- metadata +155 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://hypem.com/api/get_profile?username=jackca
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message:
|
14
|
+
headers:
|
15
|
+
server:
|
16
|
+
- nginx/1.0.12
|
17
|
+
date:
|
18
|
+
- Sat, 24 Mar 2012 22:07:39 GMT
|
19
|
+
content-type:
|
20
|
+
- text/javascript; charset=UTF-8
|
21
|
+
transfer-encoding:
|
22
|
+
- chunked
|
23
|
+
connection:
|
24
|
+
- close
|
25
|
+
set-cookie:
|
26
|
+
- AUTH=03%3A1536f8f35d43a41d289bf5cbf9e227d7%3A1332626858%3A1276002699%3ACA-US;
|
27
|
+
expires=Mon, 20-Mar-2028 22:07:38 GMT; path=/; domain=hypem.com
|
28
|
+
x-hacker:
|
29
|
+
- Hey, if you're reading this, you should drop us an email at hypem.com/contact,
|
30
|
+
maybe we can work together!
|
31
|
+
access-control-allow-origin:
|
32
|
+
- ! '*'
|
33
|
+
access-control-allow-headers:
|
34
|
+
- ! '*'
|
35
|
+
vary:
|
36
|
+
- Accept-Encoding
|
37
|
+
body:
|
38
|
+
encoding: ASCII-8BIT
|
39
|
+
string: ! '{"username":"JackCA","profile_url":"http:\/\/hypem.com\/JackCA","fullname":"Jack
|
40
|
+
Anderson","twitter_username":"janderson","userpic":"http:\/\/faces-s3.hypem.com\/123376863051420_75.png","joined_ts":1238371615,"favorites_count":{"user":4,"item":430,"site":32,"query":15,"followers":1},"location":"San
|
41
|
+
Francisco, CA, US"}'
|
42
|
+
http_version:
|
43
|
+
recorded_at: Sat, 24 Mar 2012 22:07:39 GMT
|
44
|
+
recorded_with: VCR 2.0.0
|
data/hypem.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "hypem/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "hypem"
|
7
|
+
s.version = Hypem::VERSION
|
8
|
+
s.authors = ["Jack Anderson"]
|
9
|
+
s.email = ["jackcanderson@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = "a light Ruby wrapper for the Hype Machine public API"
|
12
|
+
|
13
|
+
s.rubyforge_project = "hypem"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency "rspec", "~> 2.6"
|
21
|
+
s.add_development_dependency "vcr", "~> 2.0"
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_dependency 'faraday', '~> 0.7'
|
24
|
+
s.add_dependency 'multi_json', '~> 1.1'
|
25
|
+
s.add_dependency 'hashie', '~> 1.2'
|
26
|
+
|
27
|
+
end
|
data/lib/hypem.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "hypem/response"
|
2
|
+
require "hypem/request"
|
3
|
+
require "hypem/user"
|
4
|
+
require "hypem/track"
|
5
|
+
require "hypem/playlist"
|
6
|
+
|
7
|
+
module Hypem
|
8
|
+
|
9
|
+
#convenient way of accessing module classes
|
10
|
+
def self.method_missing(method, *args)
|
11
|
+
method_name = method.capitalize
|
12
|
+
raise ArgumentError unless self.const_defined? method_name
|
13
|
+
if args.empty?
|
14
|
+
self.const_get(method_name)
|
15
|
+
else
|
16
|
+
self.const_get(method_name).send(:new, *args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Hypem
|
2
|
+
class Playlist
|
3
|
+
POPULAR_ARGS = [%s(3day),:lastweek,:noremix,:artists,:twitter]
|
4
|
+
GENERIC_METHODS = [:blog, :tags, :search, :artist, :feed, :loved, :obsessed]
|
5
|
+
attr_accessor :url, :tracks
|
6
|
+
attr_reader :extended
|
7
|
+
|
8
|
+
def initialize(type,arg,page=1)
|
9
|
+
@type = type
|
10
|
+
@arg = arg
|
11
|
+
@page = page
|
12
|
+
@url = "/playlist/#{@type}/#{@arg}/json/#{@page}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def get
|
16
|
+
response = Request.new(url).get.response
|
17
|
+
@tracks = []
|
18
|
+
# getting rid of version cell
|
19
|
+
response.body.shift
|
20
|
+
response.body.each_value{|v| @tracks << Track.new(v)}
|
21
|
+
return self
|
22
|
+
end
|
23
|
+
|
24
|
+
def next_page
|
25
|
+
Playlist.new(@type,@arg,@page+1).get
|
26
|
+
end
|
27
|
+
|
28
|
+
def prev_page
|
29
|
+
Playlist.new(@type,@arg,@page-1).get
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.latest
|
33
|
+
Playlist.new(:time,:today).get
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.popular(arg=POPULAR_ARGS.first)
|
37
|
+
arg = arg.to_sym if arg.is_a? String
|
38
|
+
raise ArgumentError unless POPULAR_ARGS.include?(arg)
|
39
|
+
Playlist.new(:popular,arg).get
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.friends_history(user)
|
43
|
+
Playlist.new(:people_history,user).get
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.friends_favorites(user)
|
47
|
+
Playlist.new(:people,user).get
|
48
|
+
end
|
49
|
+
|
50
|
+
# meta method definitions for generic playlists
|
51
|
+
GENERIC_METHODS.each do |method|
|
52
|
+
define_singleton_method(method) {|arg| Playlist.new(method,arg).get }
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Hypem
|
4
|
+
class Request
|
5
|
+
attr_accessor :response
|
6
|
+
attr_reader :url
|
7
|
+
|
8
|
+
def initialize(url)
|
9
|
+
@url = url
|
10
|
+
end
|
11
|
+
|
12
|
+
def get
|
13
|
+
raw_response = connection.get(@url)
|
14
|
+
@response = Response.new(raw_response)
|
15
|
+
return self
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def connection
|
21
|
+
@@conn ||= Faraday.new(url: 'http://hypem.com') do |builder|
|
22
|
+
builder.request :url_encoded
|
23
|
+
#builder.response :logger
|
24
|
+
builder.adapter :net_http
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/hypem/track.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Hypem
|
4
|
+
|
5
|
+
class Track < Hashie::Trash
|
6
|
+
property :media_id, from: :mediaid
|
7
|
+
property :artist
|
8
|
+
property :title
|
9
|
+
property :date_posted, from: :dateposted
|
10
|
+
property :site_id, from: :siteid
|
11
|
+
property :sitename
|
12
|
+
property :post_url, from: :posturl
|
13
|
+
property :post_url_first, from: :posturl_first
|
14
|
+
property :post_id, from: :postid
|
15
|
+
property :date_posted_first, from: :dateposted_first
|
16
|
+
property :site_id_first, from: :siteid_first
|
17
|
+
property :site_name_first, from: :sitename_first
|
18
|
+
property :post_id_first, from: :postid_first
|
19
|
+
property :loved_count
|
20
|
+
property :posted_count
|
21
|
+
property :thumb_url
|
22
|
+
property :thumb_url_large
|
23
|
+
property :time
|
24
|
+
property :description
|
25
|
+
property :itunes_link
|
26
|
+
property :date_played, from: :dateplayed
|
27
|
+
property :date_loved, from: :dateloved
|
28
|
+
property :user_name, from: :username
|
29
|
+
property :full_name, from: :fullname
|
30
|
+
property :via_query
|
31
|
+
property :plays #used by obsessed playlist
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/hypem/user.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Hypem
|
2
|
+
class User
|
3
|
+
attr_reader :full_name, :joined_at, :location, :twitter_username, :image_url,
|
4
|
+
:followed_users_count, :followed_items_count, :followed_sites_count,
|
5
|
+
:followed_queries_count
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
raise ArgumentError unless name.is_a? String
|
9
|
+
@name = name
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_profile
|
13
|
+
response = Request.new("/api/get_profile?username=#{@name}").get.response.body
|
14
|
+
@full_name = response['fullname']
|
15
|
+
@joined_at = Time.at response['joined_ts']
|
16
|
+
@location = response['location']
|
17
|
+
@twitter_username = response['twitter_username']
|
18
|
+
@image_url = response['userpic']
|
19
|
+
@followed_users_count = response['favorites_count']['user']
|
20
|
+
@followed_items_count = response['favorites_count']['item']
|
21
|
+
@followed_sites_count = response['favorites_count']['site']
|
22
|
+
@followed_queries_count = response['favorites_count']['query']
|
23
|
+
return self
|
24
|
+
end
|
25
|
+
|
26
|
+
#playlist requests
|
27
|
+
|
28
|
+
def loved_playlist
|
29
|
+
Playlist.loved(@name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def obsessed_playlist
|
33
|
+
Playlist.obsessed(@name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def feed_playlist
|
37
|
+
Playlist.feed(@name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def friends_favorites_playlist
|
41
|
+
Playlist.friends_favorites(@name)
|
42
|
+
end
|
43
|
+
|
44
|
+
def friends_history_playlist
|
45
|
+
Playlist.friends_history(@name)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/spec/hypem_spec.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hypem::Playlist do
|
4
|
+
let(:playlist) do
|
5
|
+
VCR.use_cassette('latest_playlist'){Hypem::Playlist.latest}
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:blog_playlist) do
|
9
|
+
VCR.use_cassette('blog_playlist'){Hypem::Playlist.blog(1)}
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
context "when initialized" do
|
14
|
+
|
15
|
+
it "assigns the url attribute" do
|
16
|
+
playlist.url.should == "/playlist/time/today/json/1"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "assigns proper url for blog" do
|
20
|
+
blog_playlist.url.should == "/playlist/blog/1/json/1"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "after get" do
|
26
|
+
|
27
|
+
it "should be a playlist" do
|
28
|
+
playlist.should be_a Hypem::Playlist
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "tracks" do
|
32
|
+
it "should assign tracks attribute" do
|
33
|
+
playlist.tracks.should_not be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ".latest" do
|
39
|
+
it "returns a playlist" do
|
40
|
+
playlist.should be_a Hypem::Playlist
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ".popular" do
|
45
|
+
before {Hypem::Playlist.stub_chain(:new, :get)}
|
46
|
+
|
47
|
+
it "converts strings to symbols" do
|
48
|
+
Hypem::Playlist.should_receive(:new).with(:popular,%s(3day))
|
49
|
+
Hypem::Playlist.popular('3day')
|
50
|
+
end
|
51
|
+
|
52
|
+
it "retrieves 3day by default" do
|
53
|
+
Hypem::Playlist.should_receive(:new).with(:popular,%s(3day))
|
54
|
+
Hypem::Playlist.popular
|
55
|
+
end
|
56
|
+
|
57
|
+
it "accepts lastweek" do
|
58
|
+
Hypem::Playlist.should_receive(:new).with(:popular,:lastweek)
|
59
|
+
Hypem::Playlist.popular(:lastweek)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "accepts noremix" do
|
63
|
+
Hypem::Playlist.should_receive(:new).with(:popular,:noremix)
|
64
|
+
Hypem::Playlist.popular(:noremix)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "accepts artists" do
|
68
|
+
Hypem::Playlist.should_receive(:new).with(:popular,:artists)
|
69
|
+
Hypem::Playlist.popular(:artists)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "accepts twitter" do
|
73
|
+
Hypem::Playlist.should_receive(:new).with(:popular,:twitter)
|
74
|
+
Hypem::Playlist.popular(:twitter)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "rejects anything else" do
|
78
|
+
expect {Hypem::Playlist.popular(:no_no)}.to raise_error(ArgumentError)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "class methods" do
|
83
|
+
before {Hypem::Playlist.stub_chain(:new, :get)}
|
84
|
+
|
85
|
+
describe ".blog" do
|
86
|
+
it "calls new with type blog" do
|
87
|
+
Hypem::Playlist.should_receive(:new).with(:blog,1)
|
88
|
+
Hypem::Playlist.blog(1)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe ".tags" do
|
93
|
+
it "calls new with type tags" do
|
94
|
+
Hypem::Playlist.should_receive(:new).with(:tags,'tag')
|
95
|
+
Hypem::Playlist.tags('tag')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe ".search" do
|
100
|
+
it "calls new with type search" do
|
101
|
+
Hypem::Playlist.should_receive(:new).with(:search,'query')
|
102
|
+
Hypem::Playlist.search('query')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe ".artist" do
|
107
|
+
it "calls new with type artist" do
|
108
|
+
Hypem::Playlist.should_receive(:new).with(:artist,'name')
|
109
|
+
Hypem::Playlist.artist('name')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "pagination" do
|
115
|
+
before do
|
116
|
+
playlist
|
117
|
+
Hypem::Playlist.stub_chain(:new,:get)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "can get next page" do
|
121
|
+
Hypem::Playlist.should_receive(:new).with(:time,:today,2)
|
122
|
+
playlist.next_page
|
123
|
+
end
|
124
|
+
|
125
|
+
it "also gets previous page" do
|
126
|
+
Hypem::Playlist.should_receive(:new).with(:time,:today,0)
|
127
|
+
playlist.prev_page
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hypem::Request do
|
4
|
+
|
5
|
+
let(:request) do
|
6
|
+
Hypem::Request.new('/playlist/latest/fresh/json/1')
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:response) do
|
10
|
+
VCR.use_cassette('fresh_playlist') do
|
11
|
+
request.get.response
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "at initialization" do
|
16
|
+
|
17
|
+
it "must have a url string parameter" do
|
18
|
+
expect { Hypem::Request.new }.to raise_error ArgumentError
|
19
|
+
end
|
20
|
+
|
21
|
+
it "assigns the response attribute" do
|
22
|
+
response.should be_a Hypem::Response
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
it "makes get requests" do
|
28
|
+
response.body.should_not be_nil
|
29
|
+
response.body.should_not be_empty
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|