hypem 0.1.6 → 0.2.0
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/README.md +21 -20
- data/fixtures/vcr_cassettes/single_track.yml +47 -0
- data/hypem.gemspec +0 -1
- data/lib/hypem/blog.rb +0 -2
- data/lib/hypem/playlist.rb +2 -3
- data/lib/hypem/track.rb +46 -30
- data/lib/hypem/version.rb +1 -1
- data/spec/playlist_spec.rb +43 -15
- data/spec/track_spec.rb +51 -4
- metadata +14 -24
data/README.md
CHANGED
@@ -70,31 +70,32 @@ Blogs can be retrieved using a blog's unique id via `Hypem.blog(1234)` and have
|
|
70
70
|
******
|
71
71
|
|
72
72
|
### Track ###
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
73
|
+
Tracks can be initialized using a known `media_id` via `Hypem.track('media_id')` and synced using the `get` method on any instance. Depending on the playlist type, some tracks may have more detailed attributes than other.
|
74
|
+
|
75
|
+
An example track object inspection is as follows:
|
76
|
+
|
77
|
+
```
|
78
|
+
@media_id="1jsw9",
|
79
|
+
@artist="Hot Chip",
|
80
|
+
@title="Flutes",
|
81
|
+
@date_posted=#<DateTime: 2012-06-08T16:57:00-07:00 ((2456087j,86220s,0n),-25200s,2299161j)>,
|
82
|
+
@site_id=16116,
|
83
|
+
@site_name="the untz and the indie",
|
84
|
+
@post_url="http://theuntzandtheindie.com/2012/06/08/hot-chip-party/",
|
85
|
+
@post_id=1835105,
|
86
|
+
@loved_count=9050,
|
87
|
+
@posted_count=33,
|
88
|
+
@thumb_url="http://static-ak.hypem.net/images/albumart0.gif",
|
89
|
+
@thumb_url_large="http://static-ak.hypem.net/images/blog_images/16116.png",
|
90
|
+
@time=425,
|
91
|
+
@description="Today’s Indie: If I Was Your Girlfriend (Hot Chip Cover) / Prince /// Motion Sickness / Hot Chip /// Flutes / Hot Chip So the indie extraordinaire and goddess of all things awesome is out of town up in the Pac NW gettin silly and listening to dAHnce music",
|
92
|
+
@itunes_link="http://hypem.com/go/itunes_search/Hot%20Chip"
|
93
|
+
```
|
92
94
|
|
93
95
|
******
|
94
96
|
|
95
97
|
## TODO ###
|
96
98
|
- Blogs with given tag
|
97
|
-
- Single track info
|
98
99
|
- Authenticated Requests
|
99
100
|
- Favorite a track
|
100
101
|
- Log Playback
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://hypem.com/playlist/item/1jsw9/json/1
|
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, 09 Jun 2012 02:48:22 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%3Ae48651417fd18bf71afd356c3c50506e%3A1339210102%3A1276002699%3ACA-US;
|
27
|
+
expires=Mon, 05-Jun-2028 02:48:22 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: ! '{"version":"1.1","0":{"mediaid":"1jsw9","artist":"Hot Chip","title":"Flutes","dateposted":1339199820,"siteid":16116,"sitename":"the
|
40
|
+
untz and the indie","posturl":"http:\/\/theuntzandtheindie.com\/2012\/06\/08\/hot-chip-party\/","postid":1835105,"loved_count":9049,"posted_count":33,"thumb_url":"http:\/\/static-ak.hypem.net\/images\/albumart2.gif","thumb_url_large":"http:\/\/static-ak.hypem.net\/images\/blog_images\/16116.png","time":425,"description":"Today\u2019s
|
41
|
+
Indie: If I Was Your Girlfriend (Hot Chip Cover) \/ Prince \/\/\/ Motion Sickness
|
42
|
+
\/ Hot Chip \/\/\/ Flutes \/ Hot Chip So the indie extraordinaire and goddess
|
43
|
+
of all things awesome is out of town up in the Pac NW gettin silly and listening
|
44
|
+
to dAHnce music","itunes_link":"http:\/\/hypem.com\/go\/itunes_search\/Hot%20Chip"}}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Sat, 09 Jun 2012 02:48:27 GMT
|
47
|
+
recorded_with: VCR 2.1.1
|
data/hypem.gemspec
CHANGED
data/lib/hypem/blog.rb
CHANGED
data/lib/hypem/playlist.rb
CHANGED
@@ -15,8 +15,7 @@ module Hypem
|
|
15
15
|
def get
|
16
16
|
response = Request.new(@path).tap(&:get).response
|
17
17
|
@tracks = []
|
18
|
-
# getting rid of version cell
|
19
|
-
response.body.shift
|
18
|
+
response.body.shift # getting rid of version cell
|
20
19
|
response.body.each_value{|v| @tracks << Track.new(v)}
|
21
20
|
end
|
22
21
|
|
@@ -38,7 +37,7 @@ module Hypem
|
|
38
37
|
|
39
38
|
def self.new_from_tracks(tracks)
|
40
39
|
track_params = tracks.map(&:id).join(',')
|
41
|
-
Playlist.new('set',track_params)
|
40
|
+
Playlist.new('set',track_params).tap { |p| p.tracks = tracks }
|
42
41
|
end
|
43
42
|
|
44
43
|
def self.latest(filter=:all,page=nil)
|
data/lib/hypem/track.rb
CHANGED
@@ -1,35 +1,51 @@
|
|
1
|
-
require 'hashie'
|
2
|
-
|
3
1
|
module Hypem
|
2
|
+
class Track
|
3
|
+
attr_accessor :media_id
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
5
|
+
def initialize(arg)
|
6
|
+
if arg.is_a? Hash
|
7
|
+
keys_to_attributes arg
|
8
|
+
elsif arg.is_a? String
|
9
|
+
@media_id = arg
|
10
|
+
end
|
11
|
+
end
|
32
12
|
|
33
|
-
|
13
|
+
def get
|
14
|
+
request = Request.new("/playlist/item/#{media_id}/json/1").tap(&:get)
|
15
|
+
raw_hash = request.response.body.tap(&:shift)["0"]
|
16
|
+
keys_to_attributes raw_hash
|
17
|
+
end
|
18
|
+
|
19
|
+
KEY_CONVERSIONS = {
|
20
|
+
mediaid: :media_id,
|
21
|
+
dateposted: :dated_posted,
|
22
|
+
siteid: :site_id,
|
23
|
+
posturl: :post_url,
|
24
|
+
posturl_first: :post_url_first,
|
25
|
+
postid: :post_id,
|
26
|
+
postid_first: :post_id_first,
|
27
|
+
dateposted_first: :date_posted_first,
|
28
|
+
siteid_first: :site_id_first,
|
29
|
+
sitename: :site_name,
|
30
|
+
dateposted: :date_posted,
|
31
|
+
sitename_first: :site_name_first
|
32
|
+
}
|
33
|
+
|
34
|
+
DATETIME_CONVERSIONS = [:date_posted, :date_posted_first]
|
35
|
+
|
36
|
+
private
|
34
37
|
|
38
|
+
def keys_to_attributes(raw_hash)
|
39
|
+
raw_hash.each_pair do |key,value|
|
40
|
+
converted_key = KEY_CONVERSIONS[key.to_sym]
|
41
|
+
key = converted_key unless converted_key.nil?
|
42
|
+
|
43
|
+
value = Time.at(value).to_datetime if DATETIME_CONVERSIONS.include? key
|
44
|
+
instance_variable_set("@#{key}",value)
|
45
|
+
|
46
|
+
self.class.class_eval { attr_reader key }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
35
51
|
end
|
data/lib/hypem/version.rb
CHANGED
data/spec/playlist_spec.rb
CHANGED
@@ -13,30 +13,21 @@ describe Hypem::Playlist do
|
|
13
13
|
|
14
14
|
########################################
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
its(:path) { should == "/playlist/latest/all/json/1" }
|
17
|
+
its(:tracks) { should_not be_empty }
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
describe "#url" do
|
20
|
+
it "returns the correct playlist url " do
|
21
|
+
subject.url.should == 'http://hypem.com/playlist/latest/all/json/1'
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
context "after get" do
|
25
|
-
its(:tracks) { should_not be_empty }
|
26
|
-
end
|
27
|
-
|
28
25
|
describe ".new_from_tracks" do
|
29
26
|
let(:tracks) {[mock('Hypem::Track',id: 'track1',), mock('Hypem::Track',id:'track2')]}
|
30
27
|
subject { Hypem::Playlist.new_from_tracks(tracks) }
|
31
28
|
it { should be_a Hypem::Playlist }
|
32
29
|
its(:path) { should == '/playlist/set/track1,track2/json/1' }
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "#url" do
|
37
|
-
it "returns the correct playlist url " do
|
38
|
-
subject.url.should == 'http://hypem.com/playlist/latest/all/json/1'
|
39
|
-
end
|
30
|
+
its(:tracks) { should_not be_empty }
|
40
31
|
end
|
41
32
|
|
42
33
|
describe ".latest" do
|
@@ -121,6 +112,43 @@ describe Hypem::Playlist do
|
|
121
112
|
end
|
122
113
|
end
|
123
114
|
|
115
|
+
shared_examples_for "generic method" do
|
116
|
+
before do
|
117
|
+
Hypem::Playlist.any_instance.stub(:get)
|
118
|
+
end
|
119
|
+
specify { described_class.send(method,:an_argument).should be_a described_class }
|
120
|
+
end
|
121
|
+
|
122
|
+
describe ".blog" do
|
123
|
+
let(:method) { :blog }
|
124
|
+
it_should_behave_like "generic method"
|
125
|
+
end
|
126
|
+
|
127
|
+
describe ".search" do
|
128
|
+
let(:method) { :search }
|
129
|
+
it_should_behave_like "generic method"
|
130
|
+
end
|
131
|
+
|
132
|
+
describe ".artist" do
|
133
|
+
let(:method) { :artist }
|
134
|
+
it_should_behave_like "generic method"
|
135
|
+
end
|
136
|
+
|
137
|
+
describe ".feed" do
|
138
|
+
let(:method) { :feed }
|
139
|
+
it_should_behave_like "generic method"
|
140
|
+
end
|
141
|
+
|
142
|
+
describe ".loved" do
|
143
|
+
let(:method) { :loved }
|
144
|
+
it_should_behave_like "generic method"
|
145
|
+
end
|
146
|
+
|
147
|
+
describe ".obsessed" do
|
148
|
+
let(:method) { :obsessed }
|
149
|
+
it_should_behave_like "generic method"
|
150
|
+
end
|
151
|
+
|
124
152
|
describe "pagination" do
|
125
153
|
before do
|
126
154
|
playlist
|
data/spec/track_spec.rb
CHANGED
@@ -3,14 +3,61 @@ require 'spec_helper'
|
|
3
3
|
describe Hypem::Track do
|
4
4
|
let(:track_hash) do
|
5
5
|
VCR.use_cassette('latest_playlist') do
|
6
|
-
Hypem::Playlist.
|
6
|
+
Hypem::Playlist.any_instance.stub(:get)
|
7
|
+
path = Hypem::Playlist.latest.path
|
8
|
+
# TODO this is fucking gross
|
9
|
+
Hypem::Request.new(path).tap(&:get).response.body.tap(&:shift)["0"]
|
7
10
|
end
|
8
11
|
end
|
9
12
|
|
10
|
-
let(:
|
13
|
+
let(:media_id) { '1jsw9' }
|
14
|
+
let(:track_from_hash) { described_class.new(track_hash) }
|
15
|
+
let(:track_from_string) { described_class.new(media_id) }
|
11
16
|
|
12
|
-
|
13
|
-
|
17
|
+
shared_examples_for "a basic synced instance" do
|
18
|
+
its(:media_id) { should be_a String }
|
19
|
+
its(:artist) { should be_a String }
|
20
|
+
its(:title) { should be_a String }
|
21
|
+
its(:date_posted) { should be_a DateTime }
|
22
|
+
its(:site_id) { should be_an Integer }
|
23
|
+
its(:site_name) { should be_a String }
|
24
|
+
its(:post_url) { should be_a String }
|
25
|
+
its(:post_id) { should be_an Integer }
|
26
|
+
its(:loved_count) { should be_an Integer }
|
27
|
+
its(:posted_count) { should be_an Integer }
|
28
|
+
its(:thumb_url) { should be_a String }
|
29
|
+
its(:thumb_url_large) { should be_a String }
|
30
|
+
its(:time) { should be_an Integer }
|
31
|
+
its(:description) { should be_a String }
|
32
|
+
its(:itunes_link) { should be_a String }
|
33
|
+
end
|
34
|
+
|
35
|
+
shared_examples_for "a detailed synced instance" do
|
36
|
+
it_should_behave_like "a basic synced instance"
|
37
|
+
its(:post_url_first) { should be_a String }
|
38
|
+
its(:post_id_first) { should be_an Integer }
|
39
|
+
its(:site_name_first) { should be_a String }
|
40
|
+
its(:date_posted_first) { should be_a DateTime }
|
41
|
+
its(:site_id_first) { should be_an Integer }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#initialize" do
|
45
|
+
context "from a hash" do
|
46
|
+
subject { track_from_hash }
|
47
|
+
it_should_behave_like "a detailed synced instance"
|
48
|
+
end
|
49
|
+
|
50
|
+
context "from a media_id" do
|
51
|
+
subject { track_from_string }
|
52
|
+
its(:media_id) { should == media_id }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#get" do
|
57
|
+
subject do
|
58
|
+
VCR.use_cassette("single_track") { track_from_string.tap(&:get) }
|
59
|
+
end
|
60
|
+
it_should_behave_like "a basic synced instance"
|
14
61
|
end
|
15
62
|
|
16
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hypem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70340590270340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70340590270340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: vcr
|
27
|
-
requirement: &
|
27
|
+
requirement: &70340590269880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '2.0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70340590269880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70340590269500 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70340590269500
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: faraday
|
49
|
-
requirement: &
|
49
|
+
requirement: &70340590268960 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0.7'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70340590268960
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: multi_json
|
60
|
-
requirement: &
|
60
|
+
requirement: &70340590268460 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,18 +65,7 @@ dependencies:
|
|
65
65
|
version: '1.1'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: hashie
|
71
|
-
requirement: &70186325741000 !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
|
-
requirements:
|
74
|
-
- - ~>
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '1.2'
|
77
|
-
type: :runtime
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: *70186325741000
|
68
|
+
version_requirements: *70340590268460
|
80
69
|
description:
|
81
70
|
email:
|
82
71
|
- jackcanderson@gmail.com
|
@@ -101,6 +90,7 @@ files:
|
|
101
90
|
- fixtures/vcr_cassettes/loved_playlist.yml
|
102
91
|
- fixtures/vcr_cassettes/obsessed_playlist.yml
|
103
92
|
- fixtures/vcr_cassettes/popular_playlist.yml
|
93
|
+
- fixtures/vcr_cassettes/single_track.yml
|
104
94
|
- fixtures/vcr_cassettes/user_favorite_blogs.yml
|
105
95
|
- fixtures/vcr_cassettes/user_friends.yml
|
106
96
|
- fixtures/vcr_cassettes/user_profile.yml
|
@@ -142,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
132
|
version: '0'
|
143
133
|
segments:
|
144
134
|
- 0
|
145
|
-
hash:
|
135
|
+
hash: 3510540454550370987
|
146
136
|
requirements: []
|
147
137
|
rubyforge_project: hypem
|
148
138
|
rubygems_version: 1.8.10
|