dirble 0.0.1 → 0.0.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
2
  SHA1:
3
- metadata.gz: 0df8ae2244e7353f53e1dbf4a22458fc928a2eed
4
- data.tar.gz: e39e36b0dba25becdc8734376011e7dc1791f5dd
3
+ metadata.gz: 82ef9a0c07145dbd999b978246356b8f1a78f7c9
4
+ data.tar.gz: e8f1bd32e24512eb536ad4c84ea471a199db4e12
5
5
  SHA512:
6
- metadata.gz: fc4d75608532f9b29290a6d9b8717cdacfb078e3c02ecfe23d671e232f863813e10b18675a66df560d4183fd2a9b717a87241e704b7418d106dbaace13080eb0
7
- data.tar.gz: 76643a5a4a09deb653fdaacded4ee8f611e7d7a04e83a36c490d2a247238cd6495e61833e3c61e59196e02c7fbc331bea6e65cfae021c60a16dc18cf013918fe
6
+ metadata.gz: c85dc75870a0af17d63cbf686575fccfa356c520053e604f8a80efafbbece5c4b4183e22a40d6937b36bec0f2a92f5a762713e35ce08005eb9378375bb06a8a4
7
+ data.tar.gz: 09b713c00e04417542efc12a4afa07428cdb7732f61fb02a36636e72b9da1aaa4eef19f3138b5f519004bd4896013bef3ce698fad1f9c2a42ae57e8470587a76
data/dirble.gemspec CHANGED
@@ -24,10 +24,11 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "webmock"
25
25
  spec.add_development_dependency "pry-rescue"
26
26
  spec.add_development_dependency "pry"
27
+ spec.add_development_dependency 'pry-nav'
27
28
  spec.add_development_dependency "sinatra"
28
29
  spec.add_development_dependency "sinatra-contrib"
29
- spec.add_development_dependency "activesupport"
30
- spec.add_development_dependency "faraday"
31
- spec.add_development_dependency "typhoeus"
30
+ spec.add_runtime_dependency "activesupport"
31
+ spec.add_runtime_dependency "faraday"
32
+ spec.add_runtime_dependency "typhoeus"
32
33
  spec.add_development_dependency "coveralls"
33
34
  end
data/lib/dirble.rb CHANGED
@@ -5,6 +5,7 @@ require 'dirble/configurable'
5
5
  require 'dirble/connection'
6
6
  require 'dirble/category'
7
7
  require 'dirble/primary_category'
8
+ require 'dirble/song'
8
9
  require 'dirble/station'
9
10
 
10
11
  require 'dirble/version'
data/lib/dirble/song.rb CHANGED
@@ -1,8 +1,61 @@
1
1
  module Dirble
2
2
  class Song
3
- attr_accessor :id, :image_url, :name, :title, :spotify_url, :played_on
3
+ attr_accessor :id, :image_url, :name, :title, :spotify_url, :played_on, :raw
4
4
 
5
- def initialize(args)
5
+ def info
6
+ Hash(raw.fetch('info'))
7
+ end
8
+
9
+ def fetch_id
10
+ raw.fetch('_id', {}).fetch('$id', nil)
11
+ end
12
+
13
+ def fetch_image_url
14
+ info.fetch('image', nil)
15
+ end
16
+
17
+ def fetch_name
18
+ raw.fetch('name', nil)
19
+ end
20
+
21
+ def fetch_title
22
+ raw.fetch('title', nil)
23
+ end
24
+
25
+ def fetch_spotify_url
26
+ info.fetch('urls', {}).fetch('spotify', nil)
27
+ end
28
+
29
+ def date
30
+ raw.fetch('date', {})
31
+ end
32
+
33
+ def fetch_played_on
34
+ Time.at(date['sec'])
35
+ end
36
+
37
+ class << self
38
+ def factory(list_of_songs)
39
+ list_of_songs.map do |song|
40
+ build_song(song)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def build_song(song_params)
47
+ new_song = self.new
48
+ new_song.instance_eval do
49
+ self.raw = song_params
50
+ self.id = fetch_id
51
+ self.image_url = fetch_image_url
52
+ self.name = fetch_name
53
+ self.title = fetch_title
54
+ self.spotify_url = fetch_spotify_url
55
+ self.played_on = fetch_played_on
56
+ end
57
+ new_song
58
+ end
6
59
  end
7
60
  end
8
61
  end
@@ -5,7 +5,8 @@ module Dirble
5
5
  extend Dirble::SimpleApiModel
6
6
 
7
7
  attr_accessor :id, :name, :stream_url, :description, :website, :url_id,
8
- :song_history, :categories, :country, :bitrate, :status
8
+ :categories, :country, :bitrate, :status
9
+ attr_reader :song_history
9
10
 
10
11
  def initialize(options)
11
12
  self.id = options[:id]
@@ -14,6 +15,13 @@ module Dirble
14
15
  self.country = options[:country]
15
16
  self.bitrate = options[:bitrate]
16
17
  self.status = options[:status]
18
+ self.song_history = Array(options[:songhistory])
19
+ end
20
+
21
+ private
22
+
23
+ def song_history=(list_of_songs)
24
+ @song_history ||= Dirble::Song.factory(list_of_songs)
17
25
  end
18
26
 
19
27
  class << self
@@ -27,6 +35,13 @@ module Dirble
27
35
  ).first
28
36
  end
29
37
 
38
+ def find(station_id)
39
+ call_api_with_results(
40
+ request_type: :get,
41
+ query: "station/apikey/{{api_key}}/id/#{station_id}"
42
+ ).first
43
+ end
44
+
30
45
  def search(keyword)
31
46
  call_api_with_results(
32
47
  request_type: :get,
@@ -1,3 +1,3 @@
1
1
  module Dirble
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/station_spec.rb CHANGED
@@ -26,11 +26,17 @@ describe Dirble::Station do
26
26
  it 'gets individual station' do
27
27
 
28
28
  end
29
+
30
+ it 'owns song history' do
31
+ station = Dirble::Station.find(100)
32
+ #expect(station.song_history).to_not be_empty
33
+ expect(station.song_history.first.name).to eq('Blackfoot')
34
+ end
29
35
  end
30
36
 
31
37
  context 'create' do
32
38
  it 'creates station with status 1 when valid params' do
33
- params_for_creation = {
39
+ params_for_creation = {
34
40
  name: 'New station',
35
41
  website: 'www.new-station.com',
36
42
  directory: 'Pop'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dirble
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Przemek Mroczek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-06 00:00:00.000000000 Z
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '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'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: sinatra
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +143,7 @@ dependencies:
129
143
  - - ">="
130
144
  - !ruby/object:Gem::Version
131
145
  version: '0'
132
- type: :development
146
+ type: :runtime
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
@@ -143,7 +157,7 @@ dependencies:
143
157
  - - ">="
144
158
  - !ruby/object:Gem::Version
145
159
  version: '0'
146
- type: :development
160
+ type: :runtime
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
@@ -157,7 +171,7 @@ dependencies:
157
171
  - - ">="
158
172
  - !ruby/object:Gem::Version
159
173
  version: '0'
160
- type: :development
174
+ type: :runtime
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements: