purdie 0.0.3 → 0.0.4

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.
@@ -0,0 +1,41 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.vimeo.com/videos/117102891
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - bearer d101f5c2b664609057de84a099964b09
12
+ Accept:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Tue, 03 Mar 2015 17:44:01 GMT
21
+ Server:
22
+ - Apache
23
+ Vary:
24
+ - Accept,Vimeo-Client-Id,Accept-Encoding
25
+ Cache-Control:
26
+ - no-cache, max-age=315360000
27
+ Expires:
28
+ - Fri, 28 Feb 2025 17:44:01 GMT
29
+ Content-Length:
30
+ - '3688'
31
+ Content-Type:
32
+ - application/vnd.vimeo.video+json
33
+ Via:
34
+ - 1.1 fra1-10
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"uri":"/videos/117102891","name":"Bernard","description":null,"link":"https://vimeo.com/117102891","duration":239,"width":1280,"language":null,"height":720,"created_time":"2015-01-18T17:26:10+00:00","modified_time":"2015-02-25T21:11:06+00:00","content_rating":["unrated"],"license":"by-nc-sa","privacy":{"view":"anybody","embed":"public","download":true,"add":true,"comments":"anybody"},"pictures":{"uri":"/videos/117102891/pictures/503683214","active":true,"sizes":[{"width":100,"height":75,"link":"https://i.vimeocdn.com/video/503683214_100x75.jpg"},{"width":200,"height":150,"link":"https://i.vimeocdn.com/video/503683214_200x150.jpg"},{"width":295,"height":166,"link":"https://i.vimeocdn.com/video/503683214_295x166.jpg"},{"width":640,"height":360,"link":"https://i.vimeocdn.com/video/503683214_640x360.jpg"},{"width":960,"height":540,"link":"https://i.vimeocdn.com/video/503683214_960x540.jpg"},{"width":1280,"height":720,"link":"https://i.vimeocdn.com/video/503683214_1280x720.jpg"}]},"tags":[],"stats":{"plays":18},"embed":{"buttons":{"like":true,"watchlater":true,"share":true,"embed":true,"hd":false,"fullscreen":true,"scaling":true},"logos":{"vimeo":true,"custom":{"active":false,"link":null,"sticky":false}},"title":{"name":"user","owner":"user","portrait":"user"},"playbar":true,"volume":true,"color":"00adef"},"metadata":{"connections":{"comments":{"uri":"/videos/117102891/comments","options":["GET","POST"],"total":0},"credits":{"uri":"/videos/117102891/credits","options":["GET","POST"],"total":1},"likes":{"uri":"/videos/117102891/likes","options":["GET"],"total":0},"pictures":{"uri":"/videos/117102891/pictures","options":["GET","POST"],"total":1},"texttracks":{"uri":"/videos/117102891/texttracks","options":["GET","POST"],"total":0}},"interactions":{"watchlater":{"added":false,"added_time":null,"uri":"/users/33772623/watchlater/117102891"}}},"embed_presets":null,"user":{"uri":"/users/33772623","name":"Raw
38
+ Funk Maharishi","link":"https://vimeo.com/rawfunkmaharishi","location":null,"bio":null,"created_time":"2014-10-27T12:06:25+00:00","account":"basic","pictures":{"uri":"/users/33772623/pictures/8588995","active":true,"sizes":[{"width":30,"height":30,"link":"https://i.vimeocdn.com/portrait/8588995_30x30.jpg"},{"width":75,"height":75,"link":"https://i.vimeocdn.com/portrait/8588995_75x75.jpg"},{"width":100,"height":100,"link":"https://i.vimeocdn.com/portrait/8588995_100x100.jpg"},{"width":300,"height":300,"link":"https://i.vimeocdn.com/portrait/8588995_300x300.jpg"}]},"websites":[{"name":"http://rawfunkmaharishi.uk/","link":"http://rawfunkmaharishi.uk/","description":null}],"metadata":{"connections":{"activities":{"uri":"/users/33772623/activities","options":["GET"]},"albums":{"uri":"/users/33772623/albums","options":["GET"],"total":0},"channels":{"uri":"/users/33772623/channels","options":["GET"],"total":0},"feed":{"uri":"/users/33772623/feed","options":["GET"]},"followers":{"uri":"/users/33772623/followers","options":["GET"],"total":0},"following":{"uri":"/users/33772623/following","options":["GET"],"total":0},"groups":{"uri":"/users/33772623/groups","options":["GET"],"total":0},"likes":{"uri":"/users/33772623/likes","options":["GET"],"total":0},"portfolios":{"uri":"/users/33772623/portfolios","options":["GET"],"total":0},"videos":{"uri":"/users/33772623/videos","options":["GET"],"total":4},"watchlater":{"uri":"/users/33772623/watchlater","options":["GET"],"total":0},"shared":{"uri":"/users/33772623/shared/videos","options":["GET"],"total":0},"pictures":{"uri":"/users/33772623/pictures","options":["GET","POST"],"total":1}}},"content_filter":["language","drugs","violence","nudity","safe","unrated"]},"app":null,"status":"available"}'
39
+ http_version:
40
+ recorded_at: Tue, 03 Mar 2015 17:44:01 GMT
41
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,4 @@
1
+ Before do
2
+ FileUtils.mkdir_p "tmp/aruba/config/"
3
+ FileUtils.cp "#{$fixtures}/config/purdie.yaml", "tmp/aruba/config/"
4
+ end
@@ -0,0 +1,17 @@
1
+ @vcr
2
+ Feature: Vimeo
3
+
4
+ Scenario: Generate Vimeo YAML
5
+ Given a file named "_sources/vimeo" with:
6
+ """
7
+ https://vimeo.com/117102891
8
+ """
9
+ When I successfully run `purdie fetch`
10
+ Then a file named "_data/vimeo.yaml" should exist
11
+ And the file "_data/vimeo.yaml" should contain:
12
+ """
13
+ - title: Bernard
14
+ id: 117102891
15
+ license: Attribution-NonCommercial-ShareAlike
16
+ license_url: http://creativecommons.org/licenses/by-nc-sa/3.0/
17
+ """
@@ -15,6 +15,9 @@ module Purdie
15
15
  f = Purdie::Services::Flickr.new @config
16
16
  flickrs = []
17
17
 
18
+ v = Purdie::Services::Vimeo.new @config
19
+ vimeos = []
20
+
18
21
  sources = Dir.entries(@config['source-dir']).select { |e| e !~ /^\./ }
19
22
  sources.each do |source|
20
23
  lines = File.readlines "#{@config['source-dir']}/#{source}"
@@ -25,18 +28,26 @@ module Purdie
25
28
 
26
29
  when /flickr/
27
30
  flickrs.push f.refine line
31
+
32
+ when /vimeo/
33
+ vimeos.push v.refine line
28
34
  end
29
35
  end
30
36
  end
31
37
 
32
- FileUtils.mkdir @config['output-dir']
33
- sf = File.open '_data/soundcloud.yaml', 'w'
38
+ FileUtils.mkdir_p @config['output-dir']
39
+
40
+ sf = File.open "#{@config['output-dir']}/#{@config['services']['SoundCloud']['output-file']}", 'w'
34
41
  sf.write sounds.to_yaml
35
42
  sf.close
36
43
 
37
- ff = File.open '_data/flickr.yaml', 'w'
44
+ ff = File.open "#{@config['output-dir']}/#{@config['services']['Flickr']['output-file']}", 'w'
38
45
  ff.write flickrs.to_yaml
39
46
  ff.close
47
+
48
+ vf = File.open "#{@config['output-dir']}/#{@config['services']['Vimeo']['output-file']}", 'w'
49
+ vf.write vimeos.to_yaml
50
+ vf.close
40
51
  end
41
52
  end
42
53
  end
data/lib/purdie/config.rb CHANGED
@@ -5,8 +5,8 @@ module Purdie
5
5
  def initialize
6
6
  @conf = YAML.load File.read File.join(File.dirname(__FILE__), '..', '..', 'config/defaults.yaml')
7
7
 
8
- if File.exists? File.join(File.dirname(__FILE__), '..', '..', 'config/purdie.yaml')
9
- y = YAML.load File.read File.join(File.dirname(__FILE__), '..', '..', 'config/purdie.yaml')
8
+ if File.exists? 'config/purdie.yaml'
9
+ y = YAML.load File.read 'config/purdie.yaml'
10
10
  @conf.deep_merge! y
11
11
  end
12
12
  end
@@ -18,9 +18,6 @@ module Purdie
18
18
  url = url[0..-2] if url[-1] == '/'
19
19
  id = url.split('/')[-1].to_i
20
20
 
21
- # require 'pry'
22
- # binding.pry
23
- # flickr = FlickRaw::Flickr.new
24
21
  flickr.photos.getInfo(photo_id: id)
25
22
  end
26
23
 
@@ -44,6 +41,9 @@ module Purdie
44
41
  results['photographer'] = snapper['raw'].split(':')[1]
45
42
  rescue NoMethodError
46
43
  results['photographer'] = @config['photographer-lookups'][photo['owner']['username']]
44
+ unless results['photographer']
45
+ results['photographer'] = photo['owner']['username']
46
+ end
47
47
  end
48
48
 
49
49
  results
@@ -11,7 +11,7 @@ module Purdie
11
11
 
12
12
  def all_tracks
13
13
  @all_tracks ||= begin
14
- url = "#{@config['soundcloud']['host']}/users/#{ENV['SOUNDCLOUD_USER_ID']}/tracks?client_id=#{ENV['SOUNDCLOUD_CLIENT_ID']}"
14
+ url = "#{@config['services']['SoundCloud']['host']}/users/#{ENV['SOUNDCLOUD_USER_ID']}/tracks?client_id=#{ENV['SOUNDCLOUD_CLIENT_ID']}"
15
15
  response = HTTParty.get url
16
16
  JSON.parse response.body
17
17
  end
@@ -0,0 +1,40 @@
1
+ require 'purdie'
2
+
3
+ Dotenv.load
4
+
5
+ module Purdie
6
+ module Services
7
+ class Vimeo
8
+ def initialize config
9
+ @config = config
10
+ end
11
+
12
+ def get_video url
13
+ url.strip!
14
+ url = url[0..-2] if url[-1] == '/'
15
+ @id = url.split('/')[-1].to_i
16
+
17
+ target = "#{@config['services']['Vimeo']['host']}/videos/#{@id}"
18
+ headers = {
19
+ 'Authorization' => "bearer #{ENV['VIMEO_BEARER_TOKEN']}",
20
+ 'Accept' => 'application/json'
21
+ }
22
+ response = HTTParty.get target, headers: headers
23
+
24
+ JSON.parse response.body
25
+ end
26
+
27
+ def refine url
28
+ video = get_video url
29
+ results = {}
30
+
31
+ results['title'] = video['name']
32
+ results['id'] = @id
33
+ results['license'] = @config['license-lookups'][video['license']]['full-name']
34
+ results['license_url'] = @config['license-lookups'][video['license']]['url']
35
+
36
+ results
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module Purdie
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/purdie.rb CHANGED
@@ -10,6 +10,7 @@ require 'purdie/config'
10
10
 
11
11
  require 'purdie/services/soundcloud'
12
12
  require 'purdie/services/flickr'
13
+ require 'purdie/services/vimeo'
13
14
 
14
15
  module Purdie
15
16
  def Purdie.strip_scheme url
data/spec/config_spec.rb CHANGED
@@ -8,13 +8,8 @@ module Purdie
8
8
  end
9
9
 
10
10
  it 'reads a local config file' do
11
- FileUtils.cp File.join(File.dirname(__FILE__), '..', 'features/support/fixtures/config/purdie.yaml'),
12
- File.join(File.dirname(__FILE__), '..', 'config/purdie.yaml')
13
-
14
11
  c = Config.new
15
12
  expect(c['default-title']).to eq 'Raw Funk Maharishi'
16
-
17
- FileUtils.rm File.join(File.dirname(__FILE__), '..', 'config/purdie.yaml')
18
13
  end
19
14
  end
20
15
  end
@@ -3,19 +3,10 @@ require 'spec_helper'
3
3
  module Purdie
4
4
  module Services
5
5
  describe Flickr do
6
- before :all do
7
- FileUtils.cp File.join(File.dirname(__FILE__), '..', '..', 'features/support/fixtures/config/purdie.yaml'),
8
- File.join(File.dirname(__FILE__), '..', '..', 'config/purdie.yaml')
9
- end
10
-
11
6
  before :each do
12
7
  @f = Flickr.new Config.new
13
8
  end
14
9
 
15
- after :all do
16
- FileUtils.rm File.join(File.dirname(__FILE__), '..', '..', 'config/purdie.yaml')
17
- end
18
-
19
10
  it 'refines data for a regular photo', :vcr do
20
11
  expect(@f.refine 'https://www.flickr.com/photos/rawfunkmaharishi/15631479625/').to eq({
21
12
  "title"=>"The Comedy, October 2014",
@@ -39,6 +30,10 @@ module Purdie
39
30
  "photographer"=>"jane"
40
31
  })
41
32
  end
33
+
34
+ it 'falls back to the default photographer name', :vcr do
35
+ expect(@f.refine('https://www.flickr.com/photos/pikesley/16649739916/')['photographer']).to eq 'pikesley'
36
+ end
42
37
  end
43
38
  end
44
39
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module Purdie
4
+ module Services
5
+ describe Vimeo do
6
+ before :each do
7
+ @v = Vimeo.new Config.new
8
+ end
9
+
10
+ it 'gets a video', :vcr do
11
+ expect(@v.get_video 'https://vimeo.com/117102891').to be_a Hash
12
+ end
13
+
14
+ it 'refines a video', :vcr do
15
+ expect(@v.refine 'https://vimeo.com/117102891').to eq({
16
+ "title"=>"Bernard",
17
+ "id"=>117102891,
18
+ "license"=>"Attribution-NonCommercial-ShareAlike",
19
+ "license_url"=>"http://creativecommons.org/licenses/by-nc-sa/3.0/"
20
+ })
21
+ end
22
+ end
23
+ end
24
+ end
data/spec/spec_helper.rb CHANGED
@@ -14,4 +14,13 @@ RSpec.configure do |config|
14
14
  config.filter_run :focus
15
15
  config.run_all_when_everything_filtered = true
16
16
  config.order = :random
17
+
18
+ config.before :each do
19
+ FileUtils.cp File.join(File.dirname(__FILE__), '..', 'features/support/fixtures/config/purdie.yaml'),
20
+ File.join(File.dirname(__FILE__), '..', 'config/purdie.yaml')
21
+ end
22
+
23
+ config.after :each do
24
+ FileUtils.rm File.join(File.dirname(__FILE__), '..', 'config/purdie.yaml')
25
+ end
17
26
  end
@@ -0,0 +1,122 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.flickr.com/services/rest/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: photo_id=16649739916&method=flickr.photos.getInfo&format=json&nojsoncallback=1
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - FlickRaw/0.9.8
16
+ Authorization:
17
+ - OAuth realm="https://api.flickr.com/services/rest/", oauth_consumer_key="<FLICKR_API_KEY>",
18
+ oauth_nonce="6Myoiw%2BiAA7g2sP4Z5tnoU7%2B9hR%2FdqtMPx6eFQLK%2F1I%3D", oauth_signature="<FLICKR_SECRET>%26",
19
+ oauth_signature_method="PLAINTEXT", oauth_timestamp="1425307190", oauth_token="",
20
+ oauth_version="1.0"
21
+ Content-Type:
22
+ - application/x-www-form-urlencoded
23
+ response:
24
+ status:
25
+ code: 200
26
+ message: OK
27
+ headers:
28
+ Date:
29
+ - Mon, 02 Mar 2015 14:39:59 GMT
30
+ Content-Type:
31
+ - application/json
32
+ Content-Length:
33
+ - '543'
34
+ P3p:
35
+ - policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV
36
+ TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY
37
+ ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
38
+ Cache-Control:
39
+ - private
40
+ X-Served-By:
41
+ - www30.flickr.bf1.yahoo.com
42
+ Vary:
43
+ - Accept-Encoding
44
+ Age:
45
+ - '0'
46
+ Via:
47
+ - http/1.1 fts113.flickr.bf1.yahoo.com (ApacheTrafficServer/4.0.2 [cMsSf ]),
48
+ http/1.1 r15.ycpi.dea.yahoo.net (ApacheTrafficServer [cMsSf ])
49
+ Server:
50
+ - ATS
51
+ Connection:
52
+ - keep-alive
53
+ body:
54
+ encoding: ASCII-8BIT
55
+ string: '{"photo":{"id":"16649739916","secret":"a575f69e94","server":"8661","farm":9,"dateuploaded":"1425159508","isfavorite":0,"license":"1","safety_level":"0","rotation":0,"originalsecret":"e33e9d3d4a","originalformat":"jpg","owner":{"nsid":"73135567@N00","username":"pikesley","realname":"Sam","location":"London","iconserver":"5072","iconfarm":6,"path_alias":"pikesley"},"title":{"_content":"Catface"},"description":{"_content":""},"visibility":{"ispublic":1,"isfriend":0,"isfamily":0},"dates":{"posted":"1425159508","taken":"2015-02-28
56
+ 22:36:25","takengranularity":"0","takenunknown":"0","lastupdate":"1425159602"},"views":"19","editability":{"cancomment":0,"canaddmeta":0},"publiceditability":{"cancomment":1,"canaddmeta":0},"usage":{"candownload":1,"canblog":0,"canprint":0,"canshare":1},"comments":{"_content":"0"},"notes":{"note":[]},"people":{"haspeople":0},"tags":{"tag":[]},"urls":{"url":[{"type":"photopage","_content":"https:\/\/www.flickr.com\/photos\/pikesley\/16649739916\/"}]},"media":"photo"},"stat":"ok"}'
57
+ http_version:
58
+ recorded_at: Mon, 02 Mar 2015 14:39:59 GMT
59
+ - request:
60
+ method: post
61
+ uri: https://api.flickr.com/services/rest/
62
+ body:
63
+ encoding: US-ASCII
64
+ string: method=flickr.photos.licenses.getInfo&format=json&nojsoncallback=1
65
+ headers:
66
+ Accept-Encoding:
67
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
68
+ Accept:
69
+ - "*/*"
70
+ User-Agent:
71
+ - FlickRaw/0.9.8
72
+ Authorization:
73
+ - OAuth realm="https://api.flickr.com/services/rest/", oauth_consumer_key="<FLICKR_API_KEY>",
74
+ oauth_nonce="2T5dLPn6PimygG664wjU5l7XkhPrU0ceUD3z53FpGZs%3D", oauth_signature="<FLICKR_SECRET>%26",
75
+ oauth_signature_method="PLAINTEXT", oauth_timestamp="1425307199", oauth_token="",
76
+ oauth_version="1.0"
77
+ Content-Type:
78
+ - application/x-www-form-urlencoded
79
+ response:
80
+ status:
81
+ code: 200
82
+ message: OK
83
+ headers:
84
+ Date:
85
+ - Mon, 02 Mar 2015 14:39:59 GMT
86
+ Content-Type:
87
+ - application/json
88
+ Content-Length:
89
+ - '314'
90
+ P3p:
91
+ - policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV
92
+ TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY
93
+ ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
94
+ Cache-Control:
95
+ - private
96
+ X-Served-By:
97
+ - www304.flickr.bf1.yahoo.com
98
+ Vary:
99
+ - Accept-Encoding
100
+ Age:
101
+ - '0'
102
+ Via:
103
+ - http/1.1 fts117.flickr.bf1.yahoo.com (ApacheTrafficServer/4.0.2 [cMsSf ]),
104
+ http/1.1 r12.ycpi.dea.yahoo.net (ApacheTrafficServer [cMsSf ])
105
+ Server:
106
+ - ATS
107
+ Connection:
108
+ - keep-alive
109
+ body:
110
+ encoding: ASCII-8BIT
111
+ string: '{"licenses":{"license":[{"id":"0","name":"All Rights Reserved","url":""},{"id":"4","name":"Attribution
112
+ License","url":"https:\/\/creativecommons.org\/licenses\/by\/2.0\/"},{"id":"6","name":"Attribution-NoDerivs
113
+ License","url":"https:\/\/creativecommons.org\/licenses\/by-nd\/2.0\/"},{"id":"3","name":"Attribution-NonCommercial-NoDerivs
114
+ License","url":"https:\/\/creativecommons.org\/licenses\/by-nc-nd\/2.0\/"},{"id":"2","name":"Attribution-NonCommercial
115
+ License","url":"https:\/\/creativecommons.org\/licenses\/by-nc\/2.0\/"},{"id":"1","name":"Attribution-NonCommercial-ShareAlike
116
+ License","url":"https:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.0\/"},{"id":"5","name":"Attribution-ShareAlike
117
+ License","url":"https:\/\/creativecommons.org\/licenses\/by-sa\/2.0\/"},{"id":"7","name":"No
118
+ known copyright restrictions","url":"https:\/\/www.flickr.com\/commons\/usage\/"},{"id":"8","name":"United
119
+ States Government Work","url":"http:\/\/www.usa.gov\/copyright.shtml"}]},"stat":"ok"}'
120
+ http_version:
121
+ recorded_at: Mon, 02 Mar 2015 14:39:59 GMT
122
+ recorded_with: VCR 2.9.3