hypem 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -51,7 +51,7 @@ This is an unoffical Ruby gem for the **Hype Machine** read-only API. It support
51
51
  </tbody>
52
52
  </table>
53
53
 
54
- Each playlist has a `tracks` attribute containing an array of `Hypem::Tracks`'s. Pagination is supported with the `.next_page` and `.prev_page` methods.
54
+ Each playlist has a `tracks` attribute containing an array of `Hypem::Tracks`'s. Pagination is supported with the `.next_page` and `.prev_page`, `page(num)` methods.
55
55
 
56
56
  ******
57
57
 
@@ -13,8 +13,11 @@ module Hypem
13
13
  end
14
14
 
15
15
  def get_info
16
- response = Request.new("/api/get_site_info?siteid=#{@id}").get.response.body
17
- update_from_response(response)
16
+ unless @has_info
17
+ response = Request.new("/api/get_site_info?siteid=#{@id}").get.response.body
18
+ update_from_response(response)
19
+ @has_info = true
20
+ end
18
21
  return self
19
22
  end
20
23
 
@@ -5,7 +5,8 @@ module Hypem
5
5
  attr_accessor :path, :tracks
6
6
  attr_reader :extended
7
7
 
8
- def initialize(type,arg,page=1)
8
+ def initialize(type,arg,page=nil)
9
+ page = 1 if page.nil?
9
10
  @type = type
10
11
  @arg = arg
11
12
  @page = page
@@ -29,6 +30,10 @@ module Hypem
29
30
  Playlist.new(@type,@arg,@page-1).get
30
31
  end
31
32
 
33
+ def page(num)
34
+ Playlist.new(@type,@arg,num).get
35
+ end
36
+
32
37
  def self.create_url(tracks)
33
38
  raise ArgumentError if (!tracks.is_a? Array) || (!tracks.first.is_a? Hypem::Track)
34
39
  track_params = tracks.map(&:id).join(',')
@@ -36,33 +41,35 @@ module Hypem
36
41
  return Hypem::ROOT_PATH + playlist.path
37
42
  end
38
43
 
39
- def self.latest
40
- Playlist.new(:time,:today).get
44
+ def self.latest(page=nil)
45
+ Playlist.new(:time,:today,page).get
41
46
  end
42
47
 
43
- def self.popular(arg=POPULAR_ARGS.first)
48
+ def self.popular(arg=POPULAR_ARGS.first,page=nil)
44
49
  arg = arg.to_sym if arg.is_a? String
45
50
  raise ArgumentError unless POPULAR_ARGS.include?(arg)
46
- Playlist.new(:popular,arg).get
51
+ Playlist.new(:popular,arg,page).get
47
52
  end
48
53
 
49
- def self.friends_history(user)
50
- Playlist.new(:people_history,user).get
54
+ def self.friends_history(user,page=nil)
55
+ Playlist.new(:people_history,user,page).get
51
56
  end
52
57
 
53
- def self.friends_favorites(user)
54
- Playlist.new(:people,user).get
58
+ def self.friends_favorites(user,page=nil)
59
+ Playlist.new(:people,user,page).get
55
60
  end
56
61
 
57
- def self.tags(input)
58
- input = input.join(',') if input.is_a? Array
59
- Playlist.new(:tags,input)
62
+ def self.tags(list,page)
63
+ list = list.join(',') if list.is_a? Array
64
+ Playlist.new(:tags,list,page)
60
65
  end
61
66
 
62
67
 
63
68
  # meta method definitions for generic playlists
64
69
  GENERIC_METHODS.each do |method|
65
- define_singleton_method(method) {|arg| Playlist.new(method,arg).get }
70
+ define_singleton_method(method) do |arg,page=nil|
71
+ Playlist.new(method,arg,page).get
72
+ end
66
73
  end
67
74
 
68
75
  end
@@ -1,3 +1,3 @@
1
1
  module Hypem
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -18,7 +18,7 @@ describe Hypem::Blog do
18
18
  Hypem::Blog.new('4632').id.should === 4632
19
19
  end
20
20
 
21
- describe ".get_info" do
21
+ describe "#get_info" do
22
22
  subject do
23
23
  VCR.use_cassette('blog') {blog.get_info}
24
24
  end
@@ -32,6 +32,12 @@ describe Hypem::Blog do
32
32
  specify {subject.last_posted.should be_a Time}
33
33
  specify {subject.followers.should == 1345}
34
34
 
35
+ it "caches its response" do
36
+ subject
37
+ Hypem::Request.should_not_receive :new
38
+ VCR.use_cassette('blog') { blog.get_info }
39
+ end
40
+
35
41
  end
36
42
  end
37
43
 
@@ -96,33 +96,33 @@ describe Hypem::Playlist do
96
96
 
97
97
  describe ".blog" do
98
98
  it "calls new with type blog" do
99
- Hypem::Playlist.should_receive(:new).with(:blog,1)
100
- Hypem::Playlist.blog(1)
99
+ Hypem::Playlist.should_receive(:new).with(:blog,1,5)
100
+ Hypem::Playlist.blog(1,5)
101
101
  end
102
102
  end
103
103
 
104
104
  describe ".tags" do
105
105
  it "creates a tag playlist from a string" do
106
- Hypem::Playlist.should_receive(:new).with(:tags,'tag1,tag2')
107
- Hypem::Playlist.tags('tag1,tag2')
106
+ Hypem::Playlist.should_receive(:new).with(:tags,'tag1,tag2',5)
107
+ Hypem::Playlist.tags('tag1,tag2',5)
108
108
  end
109
109
  it "creates a tag playlist from an array of strings" do
110
- Hypem::Playlist.should_receive(:new).with(:tags,'tag1,tag2')
111
- Hypem::Playlist.tags(['tag1','tag2'])
110
+ Hypem::Playlist.should_receive(:new).with(:tags,'tag1,tag2',5)
111
+ Hypem::Playlist.tags(['tag1','tag2'],5)
112
112
  end
113
113
  end
114
114
 
115
115
  describe ".search" do
116
116
  it "calls new with type search" do
117
- Hypem::Playlist.should_receive(:new).with(:search,'query')
118
- Hypem::Playlist.search('query')
117
+ Hypem::Playlist.should_receive(:new).with(:search,'query',5)
118
+ Hypem::Playlist.search('query',5)
119
119
  end
120
120
  end
121
121
 
122
122
  describe ".artist" do
123
123
  it "calls new with type artist" do
124
- Hypem::Playlist.should_receive(:new).with(:artist,'name')
125
- Hypem::Playlist.artist('name')
124
+ Hypem::Playlist.should_receive(:new).with(:artist,'name',5)
125
+ Hypem::Playlist.artist('name',5)
126
126
  end
127
127
  end
128
128
  end
@@ -133,14 +133,25 @@ describe Hypem::Playlist do
133
133
  Hypem::Playlist.stub_chain(:new,:get)
134
134
  end
135
135
 
136
- it "can get next page" do
137
- Hypem::Playlist.should_receive(:new).with(:time,:today,2)
138
- playlist.next_page
136
+ describe "#next_page" do
137
+ it "gets next page" do
138
+ Hypem::Playlist.should_receive(:new).with(anything,anything,2)
139
+ playlist.next_page
140
+ end
139
141
  end
140
142
 
141
- it "also gets previous page" do
142
- Hypem::Playlist.should_receive(:new).with(:time,:today,0)
143
- playlist.prev_page
143
+ describe "#prev_page" do
144
+ it "gets previous page" do
145
+ Hypem::Playlist.should_receive(:new).with(anything,anything,0)
146
+ playlist.prev_page
147
+ end
148
+ end
149
+
150
+ describe "#page" do
151
+ it "gets any page number" do
152
+ Hypem::Playlist.should_receive(:new).with(anything,anything,5)
153
+ playlist.page(5)
154
+ end
144
155
  end
145
156
 
146
157
  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.1.2
4
+ version: 0.1.3
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-05-12 00:00:00.000000000 Z
12
+ date: 2012-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70226383951100 !ruby/object:Gem::Requirement
16
+ requirement: &70219620218660 !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: *70226383951100
24
+ version_requirements: *70219620218660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: vcr
27
- requirement: &70226383950640 !ruby/object:Gem::Requirement
27
+ requirement: &70219620218200 !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: *70226383950640
35
+ version_requirements: *70219620218200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70226383950260 !ruby/object:Gem::Requirement
38
+ requirement: &70219620217820 !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: *70226383950260
46
+ version_requirements: *70219620217820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faraday
49
- requirement: &70226383949720 !ruby/object:Gem::Requirement
49
+ requirement: &70219620217280 !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: *70226383949720
57
+ version_requirements: *70219620217280
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: multi_json
60
- requirement: &70226383949220 !ruby/object:Gem::Requirement
60
+ requirement: &70219620216780 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '1.1'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70226383949220
68
+ version_requirements: *70219620216780
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: hashie
71
- requirement: &70226383948760 !ruby/object:Gem::Requirement
71
+ requirement: &70219620216320 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '1.2'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70226383948760
79
+ version_requirements: *70219620216320
80
80
  description:
81
81
  email:
82
82
  - jackcanderson@gmail.com
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  version: '0'
141
141
  segments:
142
142
  - 0
143
- hash: 1615421271881713189
143
+ hash: -553475673543070860
144
144
  requirements: []
145
145
  rubyforge_project: hypem
146
146
  rubygems_version: 1.8.10