purdie 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -6
  3. data/README.md +38 -22
  4. data/_config/defaults.yaml +10 -0
  5. data/_data/flickr.yaml +4 -0
  6. data/_data/soundcloud.yaml +7 -0
  7. data/features/flickr-album.feature +23 -0
  8. data/features/flickr-different-size.feature +28 -0
  9. data/features/soundcloud-set.feature +41 -0
  10. data/features/soundcloud.feature +0 -1
  11. data/features/support/fixtures/vcr/A_URL_we_don_t_understand/Handle_a_URL_we_don_t_recognise.yml +16 -16
  12. data/features/support/fixtures/vcr/First_contact_with_the_Real_World/Generate_YAML_for_the_Raw_Funk_Maharishi.yml +191 -276
  13. data/features/support/fixtures/vcr/Flickr/Generate_Flickr_YAML.yml +16 -16
  14. data/features/support/fixtures/vcr/Flickr_album/Generate_Flickr_YAML_for_an_album.yml +1035 -0
  15. data/features/support/fixtures/vcr/Handle_comments/Handle_comments_in_a_source_file.yml +75 -206
  16. data/features/support/fixtures/vcr/Purdie/Generate_several_YAML.yml +177 -213
  17. data/features/support/fixtures/vcr/Select_a_file_to_process/Choose_file_to_process.yml +56 -188
  18. data/features/support/fixtures/vcr/Set_Flickr_picturesize/Generate_Flickr_YAML.yml +125 -0
  19. data/features/support/fixtures/vcr/Soundcloud/Generate_SoundCloud_YAML.yml +56 -188
  20. data/features/support/fixtures/vcr/Soundcloud/Generate_SoundCloud_YAML_for_multiple_tracks.yml +140 -181
  21. data/features/support/fixtures/vcr/Soundcloud_set/Generate_YAML_for_a_SoundCloud_set.yml +436 -0
  22. data/features/support/fixtures/vcr/Vimeo/Generate_Vimeo_YAML.yml +23 -11
  23. data/features/support/fixtures/vcr/YouTube/Generate_YouTube_YAML.yml +970 -0
  24. data/features/support/vcr.rb +7 -5
  25. data/features/youtube.feature +20 -0
  26. data/lib/purdie/bernard.rb +35 -17
  27. data/lib/purdie/cli.rb +1 -1
  28. data/lib/purdie/helpers.rb +24 -0
  29. data/lib/purdie/ingester.rb +25 -10
  30. data/lib/purdie/services/flickr.rb +48 -5
  31. data/lib/purdie/services/soundcloud.rb +13 -21
  32. data/lib/purdie/services/vimeo.rb +4 -3
  33. data/lib/purdie/services/youtube.rb +64 -0
  34. data/lib/purdie/source_list.rb +46 -0
  35. data/lib/purdie/version.rb +1 -1
  36. data/lib/purdie.rb +4 -21
  37. data/list +1 -0
  38. data/purdie.gemspec +3 -1
  39. data/spec/helpers_spec.rb +31 -0
  40. data/spec/purdie_spec.rb +0 -24
  41. data/spec/services/flickr_spec.rb +33 -1
  42. data/spec/services/soundcloud_spec.rb +10 -8
  43. data/spec/services/youtube_spec.rb +27 -0
  44. data/spec/source_list_spec.rb +64 -0
  45. data/spec/support/fixtures/soundcloud.sounds +4 -0
  46. data/spec/support/fixtures/with-comments.source +3 -0
  47. data/spec/support/vcr_setup.rb +3 -1
  48. data/spec/vcr/Purdie_Services_Flickr/distills_data_for_a_regular_photo.yml +15 -15
  49. data/spec/vcr/Purdie_Services_Flickr/falls_back_to_the_default_photographer_name.yml +16 -16
  50. data/spec/vcr/Purdie_Services_Flickr/ingests_data_for_a_photo_without_a_specific_photographer_tag.yml +16 -16
  51. data/spec/vcr/Purdie_Services_Flickr/resolve_a_set/resolves_a_set_from_a_url.yml +518 -0
  52. data/spec/vcr/Purdie_Services_SoundCloud/connects_to_SoundCloud.yml +62 -67
  53. data/spec/vcr/Purdie_Services_SoundCloud/distills_the_data.yml +53 -183
  54. data/spec/vcr/Purdie_Services_SoundCloud/extracts_a_track.yml +50 -194
  55. data/spec/vcr/Purdie_Services_SoundCloud/ingests_a_track.yml +48 -186
  56. data/spec/vcr/Purdie_Services_SoundCloud/resolve_a_set/resolves_a_set_from_a_url.yml +103 -0
  57. data/spec/vcr/Purdie_Services_Vimeo/gets_a_video.yml +23 -11
  58. data/spec/vcr/Purdie_Services_Vimeo/ingests_a_video.yml +23 -11
  59. data/spec/vcr/Purdie_Services_YouTube/gets_a_video.yml +970 -0
  60. data/spec/vcr/Purdie_Services_YouTube/ingests_a_video.yml +970 -0
  61. data/spec/vcr/Purdie_SourceList/resolve_sets/constructs_a_list_from_a_set_URL.yml +518 -0
  62. data/spec/vcr/Purdie_SourceList/resolve_sets/resolves_a_Flickr_set.yml +518 -0
  63. data/spec/vcr/Purdie_SourceList/resolve_sets/resolves_a_SoundCloud_set.yml +103 -0
  64. data/spec/vcr/Purdie_SourceList/resolves_a_Flickr_set.yml +518 -0
  65. data/wtf.log +1 -0
  66. metadata +81 -14
  67. data/features/support/fixtures/vcr/Handle_no__sources_directory/Handle_no__sources_directory.yml +0 -346
  68. data/spec/vcr/Purdie_Services_SoundCloud/deals_with_a_troublesome_bawbag.yml +0 -230
  69. data/spec/vcr/Purdie_Services_SoundCloud/refines_the_data.yml +0 -230
  70. data/spec/vcr/Purdie_Services_Vimeo/distills_a_video.yml +0 -41
  71. data/spec/vcr/Purdie_Services_Vimeo/refines_a_video.yml +0 -41
@@ -11,7 +11,9 @@ VCR.configure do |c|
11
11
  [
12
12
  'SOUNDCLOUD_CLIENT_ID',
13
13
  'FLICKR_API_KEY',
14
- 'FLICKR_SECRET'
14
+ 'FLICKR_SECRET',
15
+ 'VIMEO_BEARER_TOKEN',
16
+ 'YOUTUBE_API_KEY'
15
17
  ].each do |env_var|
16
18
  c.filter_sensitive_data("<#{env_var}>") { ENV[env_var] }
17
19
  end
@@ -22,7 +24,7 @@ VCR.cucumber_tags do |t|
22
24
  end
23
25
 
24
26
  class VcrFriendlyMain
25
- def initialize(argv, stdin, stdout, stderr, kernel)
27
+ def initialize argv, stdin, stdout, stderr, kernel
26
28
  @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
27
29
  end
28
30
 
@@ -30,16 +32,16 @@ class VcrFriendlyMain
30
32
  $stdin = @stdin
31
33
  $stdout = @stdout
32
34
  $stderr = @stderr
33
- Purdie::CLI.start(@argv)
35
+ Purdie::CLI.start @argv
34
36
  end
35
37
  end
36
38
 
37
- Before('@vcr') do
39
+ Before '@vcr' do
38
40
  Aruba::InProcess.main_class = VcrFriendlyMain
39
41
  Aruba.process = Aruba::InProcess
40
42
  end
41
43
 
42
- After('@vcr') do
44
+ After '@vcr' do
43
45
  Aruba.process = Aruba::SpawnProcess
44
46
  VCR.eject_cassette
45
47
  $stdin = STDIN
@@ -0,0 +1,20 @@
1
+ @vcr
2
+ Feature: YouTube
3
+
4
+ Scenario: Generate YouTube YAML
5
+ Given a file named "_sources/youtube.movies" with:
6
+ """
7
+ https://www.youtube.com/watch?v=Qt_J0jNqtZg&list=PLuPLM2FI60-M0-aWejF9WgB-Dkt1TuQXv&index=2
8
+ """
9
+ When I successfully run `purdie fetch`
10
+ Then a file named "_data/youtube.yaml" should exist
11
+ And the file "_data/youtube.yaml" should contain:
12
+ """
13
+ - title: Sam Pikesley – Vandalising your Github commit history for fun and profit
14
+ id: Qt_J0jNqtZg
15
+ license: Attribution
16
+ license_url: https://creativecommons.org/licenses/by/3.0/
17
+ """
18
+ And a file named "_data/soundcloud.yaml" should not exist
19
+ And a file named "_data/vimeo.yaml" should not exist
20
+ And a file named "_data/flickr.yaml" should not exist
@@ -7,37 +7,55 @@ module Purdie
7
7
  def initialize
8
8
  @config = Config.new
9
9
  begin
10
- @sources = Dir.entries(@config['source_dir']).select { |e| e !~ /^\./ }
11
- @sources.map! { |s| "#{@config['source_dir']}/#{s}"}
10
+ @sources = Dir.entries(@config['source_dir']).select { |e|
11
+ e !~ /^\./
12
+ }.map { |s|
13
+ "#{@config['source_dir']}/#{s}"
14
+ }
12
15
  rescue Errno::ENOENT
13
16
  @sources = nil
14
17
  end
15
18
  end
16
19
 
17
- def source_file path
20
+ def source_file= path
18
21
  @sources = [path]
19
22
  end
20
23
 
24
+ def services
25
+ @services ||= Ingester.ingesters.map { |i| i.new @config }
26
+ end
27
+
28
+ def process list
29
+ list.each do |line|
30
+ next if line[0] == '#'
31
+ next if line == ''
32
+
33
+ begin
34
+ print "Processing #{line.strip}... "
35
+ grab line
36
+ rescue NoMethodError => nme
37
+ puts "unrecognised URL [#{line}]" if nme.message == "undefined method `ingest' for nil:NilClass"
38
+ else
39
+ puts 'done'
40
+ end
41
+ end
42
+ end
43
+
21
44
  def fetch
22
45
  raise Exception.new 'No data sources specified' unless @sources
23
46
 
24
- services = Ingester.includees.map { |i| i.new @config }
25
-
26
47
  @sources.each do |source|
27
- File.readlines(source).each do |line|
28
- next if line[0] == '#'
29
-
30
- begin
31
- print "Processing #{line.strip}... "
32
- services.select{ |s| line =~ /#{s.matcher}/ }[0].ingest line
33
- rescue NoMethodError => nme
34
- puts 'unrecognised URL' if nme.message == "undefined method `ingest' for nil:NilClass"
35
- else
36
- puts 'done'
37
- end
38
- end
48
+ process SourceList.from_file source
39
49
  end
40
50
 
51
+ dump
52
+ end
53
+
54
+ def grab url
55
+ services.select{ |s| url =~ /#{s.class.matcher}/ }[0].ingest url
56
+ end
57
+
58
+ def dump
41
59
  services.map { |service| service.write }
42
60
  end
43
61
  end
data/lib/purdie/cli.rb CHANGED
@@ -14,7 +14,7 @@ module Purdie
14
14
  :desc => 'Specify source file to process'
15
15
  def fetch
16
16
  b = Bernard.new
17
- b.source_file options[:source_file] if options[:source_file]
17
+ b.source_file = options[:source_file] if options[:source_file]
18
18
  begin
19
19
  b.fetch
20
20
  rescue Exception => e
@@ -0,0 +1,24 @@
1
+ module Purdie
2
+ def Purdie.strip_scheme url
3
+ url.match(/http[s]?:\/\/(.*)/)[1]
4
+ end
5
+
6
+ def Purdie.sanitise_url url
7
+ url.strip!
8
+ url = url[0..-2] if url[-1] == '/'
9
+ url
10
+ end
11
+
12
+ def Purdie.get_id url
13
+ case url
14
+ when /\?.*v=/
15
+ return CGI.parse(URI.parse(url).query)['v'].first
16
+ else
17
+ Purdie.sanitise_url(url).split('/')[-1].to_i
18
+ end
19
+ end
20
+
21
+ def Purdie.basename obj
22
+ obj.class.name.to_s.split('::').last
23
+ end
24
+ end
@@ -4,14 +4,14 @@ module Purdie
4
4
  module Ingester
5
5
  attr_reader :config, :subconfig, :matcher
6
6
 
7
- INCLUDEES = []
7
+ INGESTERS = []
8
8
 
9
9
  def self.included base
10
- INCLUDEES.push base
10
+ INGESTERS.push base
11
11
  end
12
12
 
13
- def self.includees
14
- INCLUDEES
13
+ def self.ingesters
14
+ INGESTERS
15
15
  end
16
16
 
17
17
  def initialize config
@@ -22,14 +22,25 @@ module Purdie
22
22
  end
23
23
 
24
24
  def configure
25
- if @config['services']
26
- if @config['services'][Purdie.basename self]
27
- if @config['services'][Purdie.basename self]['output_file']
28
- @config['output_dir'] = File.dirname(@config['services'][Purdie.basename self]['output_file'])
29
- @output_file = File.basename(@config['services'][Purdie.basename self]['output_file'])
30
- end
25
+ @output_file = "#{Purdie.basename(self).downcase}.yaml"
26
+ # This still feels like such a hack
27
+ specific_config = @config['services'][Purdie.basename self] rescue nil
28
+
29
+ if specific_config
30
+ if specific_config['output_file']
31
+ @config['output_dir'] = File.dirname(specific_config['output_file'])
32
+ @output_file = File.basename(@config['services'][Purdie.basename self]['output_file'])
31
33
  end
34
+
35
+ @size = specific_config['size'] if specific_config['size']
32
36
  end
37
+
38
+
39
+ # Can I do something like
40
+ # @config['services'][Purdie.basename self].each do |c|
41
+ # @#{c} = c
42
+ # end
43
+ # ?
33
44
  end
34
45
 
35
46
  def ingest url
@@ -40,6 +51,10 @@ module Purdie
40
51
  @items[key]
41
52
  end
42
53
 
54
+ def count
55
+ @items.count
56
+ end
57
+
43
58
  def has_items?
44
59
  @items.count > 0
45
60
  end
@@ -8,12 +8,12 @@ FlickRaw.shared_secret = ENV['FLICKR_SECRET']
8
8
  module Purdie
9
9
  module Services
10
10
  class Flickr
11
+ attr_accessor :size
12
+
11
13
  include Purdie::Ingester
12
14
 
13
15
  def configure
14
- @matcher = 'flickr.com'
15
- @output_file = 'flickr.yaml'
16
-
16
+ @size = 240 # pixels
17
17
  super
18
18
  end
19
19
 
@@ -33,7 +33,7 @@ module Purdie
33
33
  results['title'] = @config['default_title'] if photo['title'] == ''
34
34
  results['date'] = photo['dates']['taken'].split(' ')[0]
35
35
  results['photo_page'] = photo['urls'][0]['_content']
36
- results['photo_url'] = FlickRaw.url_m(photo)
36
+ results['photo_url'] = FlickRaw.send(Flickr.url_for_size(@size), photo)
37
37
 
38
38
  license = licenses.select {|l| l['id'] == photo['license']}[0]
39
39
  results['license'] = license['name'].split(' License')[0]
@@ -43,7 +43,11 @@ module Purdie
43
43
  snapper = photo['tags'].select { |t| t['raw'] =~ /photographer/ }[0]
44
44
  results['photographer'] = snapper['raw'].split(':')[1]
45
45
  rescue NoMethodError
46
- results['photographer'] = @config['photographer_lookups'][photo['owner']['username']]
46
+ if @config['photographer_lookups']
47
+ results['photographer'] = @config['photographer_lookups'][photo['owner']['username']]
48
+ else
49
+ results['photographer'] = photo['owner']['username']
50
+ end
47
51
  unless results['photographer']
48
52
  results['photographer'] = photo['owner']['username']
49
53
  end
@@ -51,6 +55,45 @@ module Purdie
51
55
 
52
56
  results
53
57
  end
58
+
59
+ def self.url_for_size size = nil
60
+ size = 500 unless size
61
+
62
+ case
63
+ when size <= 75
64
+ return :url_s
65
+ when size <= 100
66
+ return :url_t
67
+ when size <= 150
68
+ return :url_q
69
+ when size <= 240
70
+ return :url_m
71
+ when size <= 320
72
+ return :url_n
73
+ when size <= 500
74
+ return :url
75
+ when size <= 640
76
+ return :url_z
77
+ when size <= 800
78
+ return :url_c
79
+ when size <= 1024
80
+ return :url_b
81
+ else
82
+ return :url_o
83
+ end
84
+ end
85
+
86
+ def self.resolve_set url
87
+ flickr.photosets.getPhotos(photoset_id: Purdie.get_id(url))['photo'].
88
+ map { |member| member['id'] }.
89
+ map { |id| flickr.photos.getInfo photo_id: id }.
90
+ map { |picture| picture['urls'][0]['_content'] }
91
+ end
92
+
93
+
94
+ def self.matcher
95
+ 'flickr.com'
96
+ end
54
97
  end
55
98
  end
56
99
  end
@@ -7,30 +7,12 @@ module Purdie
7
7
  class SoundCloud
8
8
  include Purdie::Ingester
9
9
 
10
- def configure
11
- @host = 'https://api.soundcloud.com'
12
- @matcher = 'soundcloud.com'
13
- @output_file = 'soundcloud.yaml'
14
-
15
- super
16
- end
17
-
18
- def all_tracks
19
- @all_tracks ||= begin
20
- url = "#{@host}/users/#{ENV['SOUNDCLOUD_USER_ID']}/tracks?client_id=#{ENV['SOUNDCLOUD_CLIENT_ID']}"
21
- response = HTTParty.get url
22
- JSON.parse response.body
23
- end
24
- end
25
-
26
- def get url
27
- all_tracks.select do |track|
28
- Purdie.strip_scheme(track['permalink_url']) == Purdie.strip_scheme(url)
29
- end[0]
10
+ def client
11
+ @client ||= ::SoundCloud.new client_id: ENV['SOUNDCLOUD_CLIENT_ID']
30
12
  end
31
13
 
32
14
  def distill url
33
- track = get url
15
+ track = client.get '/resolve', url: url
34
16
  results = {}
35
17
  results['title'] = track['title']
36
18
  results['id'] = track['id']
@@ -41,6 +23,16 @@ module Purdie
41
23
 
42
24
  results
43
25
  end
26
+
27
+ def self.matcher
28
+ 'soundcloud.com'
29
+ end
30
+
31
+ def self.resolve_set url
32
+ client = ::SoundCloud.new client_id: ENV['SOUNDCLOUD_CLIENT_ID']
33
+ client.get('/resolve', url: url).tracks.
34
+ map { |track| track['permalink_url'] }
35
+ end
44
36
  end
45
37
  end
46
38
  end
@@ -7,9 +7,6 @@ module Purdie
7
7
 
8
8
  def configure
9
9
  @host = 'https://api.vimeo.com'
10
- @matcher = 'vimeo.com'
11
- @output_file = 'vimeo.yaml'
12
-
13
10
  super
14
11
  end
15
12
 
@@ -37,6 +34,10 @@ module Purdie
37
34
 
38
35
  results
39
36
  end
37
+
38
+ def self.matcher
39
+ 'vimeo.com'
40
+ end
40
41
  end
41
42
  end
42
43
  end
@@ -0,0 +1,64 @@
1
+ require 'purdie'
2
+ require 'cgi'
3
+ require 'google/api_client'
4
+
5
+ module Purdie
6
+ module Services
7
+ class YouTube
8
+ include Ingester
9
+
10
+ def configure
11
+ @api_service_name = 'youtube'
12
+ @api_version = 'v3'
13
+ super
14
+ end
15
+
16
+ def client
17
+ @client ||= Google::APIClient.new(
18
+ key: ENV['YOUTUBE_API_KEY'],
19
+ authorization: nil,
20
+ application_name: self.class.name.split('::').first,
21
+ application_version: Purdie::VERSION
22
+ )
23
+ end
24
+
25
+ def yt_service
26
+ @yt_service ||= client.discovered_api(
27
+ @api_service_name,
28
+ @api_version
29
+ )
30
+ end
31
+
32
+ def get_data id, part
33
+ client.execute!(
34
+ api_method: yt_service.videos.list,
35
+ parameters: {
36
+ id: id,
37
+ part: part
38
+ }
39
+ )
40
+ end
41
+
42
+ def get url
43
+ data = get_data Purdie.get_id(url), 'status,snippet'
44
+ JSON.parse data.body
45
+ end
46
+
47
+ def distill url
48
+ video = get url
49
+ results = {}
50
+
51
+ results['title'] = video['items'][0]['snippet']['localized']['title']
52
+ results['id'] = Purdie.get_id(url)
53
+ results['license'] = @config['license_lookups'][video['items'][0]['status']['license']]['full_name']
54
+ results['license_url'] = @config['license_lookups'][video['items'][0]['status']['license']]['url']
55
+
56
+ results
57
+ end
58
+
59
+ def self.matcher
60
+ 'youtube.com'
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,46 @@
1
+ require 'purdie'
2
+
3
+ module Purdie
4
+ class SourceList
5
+ include Enumerable
6
+
7
+ def initialize sources
8
+ s = sources
9
+ s = [sources] unless sources.class == Array
10
+ @sources = []
11
+ s.each do |source|
12
+ case source
13
+ when /sets/
14
+ @sources += SourceList.resolve_set source
15
+ else
16
+ @sources.push source
17
+ end
18
+ end
19
+
20
+ @sources.select! { |i| i !~ /^#/ }
21
+ @sources.uniq! { |item| Purdie.strip_scheme item }
22
+ end
23
+
24
+ def [] key
25
+ @sources[key]
26
+ end
27
+
28
+ def each &block
29
+ @sources.each do |source|
30
+ if block_given?
31
+ block.call source
32
+ else
33
+ yield source
34
+ end
35
+ end
36
+ end
37
+
38
+ def self.from_file source_file
39
+ SourceList.new File.readlines(source_file).map { |l| l.strip }
40
+ end
41
+
42
+ def self.resolve_set source
43
+ Ingester.ingesters.select { |service| source =~ /#{service.matcher}/ }[0].resolve_set source
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module Purdie
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/lib/purdie.rb CHANGED
@@ -3,35 +3,18 @@ require 'yaml'
3
3
  require 'deep_merge'
4
4
  require 'httparty'
5
5
  require 'dotenv'
6
+ require 'soundcloud'
6
7
  require 'flickraw-cached'
7
8
  require 'active_support/inflector'
8
9
 
9
10
  require 'purdie/version'
11
+ require 'purdie/helpers'
10
12
  require 'purdie/bernard'
11
13
  require 'purdie/config'
12
14
  require 'purdie/ingester'
15
+ require 'purdie/source_list'
13
16
 
14
17
  require 'purdie/services/soundcloud'
15
18
  require 'purdie/services/flickr'
16
19
  require 'purdie/services/vimeo'
17
-
18
- module Purdie
19
- def Purdie.strip_scheme url
20
- url.match(/http[s]?:\/\/(.*)/)[1]
21
- end
22
-
23
- def Purdie.sanitise_url url
24
- url.strip!
25
- url = url[0..-2] if url[-1] == '/'
26
-
27
- url
28
- end
29
-
30
- def Purdie.get_id url
31
- Purdie.sanitise_url(url).split('/')[-1].to_i
32
- end
33
-
34
- def Purdie.basename obj
35
- obj.class.name.to_s.split('::').last
36
- end
37
- end
20
+ require 'purdie/services/youtube'
data/list ADDED
@@ -0,0 +1 @@
1
+ https://soundcloud.com/rawfunkmaharishi/bernard
data/purdie.gemspec CHANGED
@@ -21,9 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'thor', '~> 0.19'
22
22
  spec.add_dependency 'httparty', '~> 0.13'
23
23
  spec.add_dependency 'deep_merge', '~> 1.0'
24
- spec.add_dependency 'dotenv', '~> 1.0'
24
+ spec.add_dependency 'dotenv', '~> 2.0'
25
25
  spec.add_dependency 'flickraw-cached', '= 20120701'
26
+ spec.add_dependency 'soundcloud'
26
27
  spec.add_dependency 'activesupport'
28
+ spec.add_dependency 'google-api-client'
27
29
 
28
30
  spec.add_development_dependency 'bundler', '~> 1.7'
29
31
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ module Purdie
4
+ describe Bernard do
5
+ it 'strips a scheme' do
6
+ expect(Purdie.strip_scheme 'http://foo.bar/stuff').to eq 'foo.bar/stuff'
7
+ expect(Purdie.strip_scheme 'https://bar.foo/stuff').to eq 'bar.foo/stuff'
8
+ end
9
+
10
+ it 'sanitises a URL' do
11
+ expect(Purdie.sanitise_url 'http://foo.bar/stuff/').to eq 'http://foo.bar/stuff'
12
+ end
13
+
14
+ it 'gets an id' do
15
+ expect(Purdie.get_id 'http://foo.bar/654321').to eq 654321
16
+ expect(Purdie.get_id 'https://www.youtube.com/watch?v=JCix1XW329g').to eq 'JCix1XW329g'
17
+ end
18
+
19
+ it 'gets a basename for a class' do
20
+ module Medeski
21
+ module Martin
22
+ class Wood
23
+ end
24
+ end
25
+ end
26
+
27
+ @mmw = Medeski::Martin::Wood.new
28
+ expect(Purdie.basename @mmw).to eq 'Wood'
29
+ end
30
+ end
31
+ end
data/spec/purdie_spec.rb CHANGED
@@ -12,29 +12,5 @@ module Purdie
12
12
  b = Bernard.new
13
13
  expect {b.fetch}.to raise_error
14
14
  end
15
-
16
- it 'strips a scheme' do
17
- expect(Purdie.strip_scheme 'http://foo.bar/stuff').to eq 'foo.bar/stuff'
18
- expect(Purdie.strip_scheme 'https://bar.foo/stuff').to eq 'bar.foo/stuff'
19
- end
20
-
21
- it 'sanitises a URL' do
22
- expect(Purdie.sanitise_url 'http://foo.bar/stuff/').to eq 'http://foo.bar/stuff'
23
- end
24
-
25
- it 'gets an id' do
26
- expect(Purdie.get_id 'http://foo.bar/654321').to eq 654321
27
- end
28
-
29
- it 'gets a basename for a class' do
30
- module Medeski
31
- module Martin
32
- class Wood
33
- end
34
- end
35
- end
36
- @mmw = Medeski::Martin::Wood.new
37
- expect(Purdie.basename @mmw).to eq 'Wood'
38
- end
39
15
  end
40
16
  end
@@ -37,7 +37,39 @@ photographer: jane
37
37
  )
38
38
  end
39
39
 
40
- it 'falls back to the default photographer name', :vcr do expect(@f.distill('https://www.flickr.com/photos/pikesley/16649739916/')['photographer']).to eq 'pikesley'
40
+ it 'falls back to the default photographer name', :vcr do
41
+ expect(@f.distill('https://www.flickr.com/photos/pikesley/16649739916/')['photographer']).to eq 'pikesley'
42
+ end
43
+
44
+ context 'FlickRaw url_ methods' do
45
+ it 'gives the plain (500px) method by default' do
46
+ expect(Flickr.url_for_size).to eq :url
47
+ end
48
+
49
+ it 'gives the 75px url when we ask for 20 pixels' do
50
+ expect(Flickr.url_for_size 20).to eq :url_s
51
+ end
52
+
53
+ it 'gives the 640px url when we ask for 600 pixels' do
54
+ expect(Flickr.url_for_size 600).to eq :url_z
55
+ end
56
+
57
+ it 'gives the 500px url when we ask for it' do
58
+ expect(Flickr.url_for_size 500).to eq :url
59
+ end
60
+
61
+ it 'gives the biggest url when we ask for something larger' do
62
+ expect(Flickr.url_for_size 6000000).to eq :url_o
63
+ end
64
+ end
65
+
66
+ context 'resolve a set' do
67
+ it 'resolves a set from a url', :vcr do
68
+ set = Flickr.resolve_set 'https://www.flickr.com/photos/pikesley/sets/72157649827363868/'
69
+ expect(set.count).to eq 8
70
+ expect(set[0]).to eq 'https://www.flickr.com/photos/pikesley/16252009191/'
71
+ expect(set[7]).to eq 'https://www.flickr.com/photos/pikesley/16752239531/'
72
+ end
41
73
  end
42
74
  end
43
75
  end