Skip to content

Commit

Permalink
Insert proper photographer links
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Jan 23, 2016
1 parent 041e599 commit b1448a2
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
75 changes: 75 additions & 0 deletions features/support/vcr/Get_JSON/Get_JSON_for_photographers.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/funkdata.rb
Expand Up @@ -69,7 +69,7 @@ class App < Sinatra::Base
end

wants.html do
redirect to "http://rawfunkmaharishi.uk/"
redirect to 'http://rawfunkmaharishi.uk/'
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions lib/funkdata/fetcher.rb
Expand Up @@ -40,18 +40,29 @@ def self.get_thing thing
YAML.load get([CONFIG['github']['urls']['raw'], CONFIG['github']['paths'][thing]].join('/'))
end

def self.photographer name
get_photographers.select { |p| p['name'] == name }[0].delete_if { |k, v| v == {} }
end

def self.method_missing method_name
mname = method_name.to_s

if mname[0..3] == 'get_'
subject = mname[4..-1]
thing = self.send(:get_thing, subject)

if subject == 'videos'
thing.each do |t|
t['url'] = "https://vimeo.com/#{t['id']}"
end
end

if subject == 'pictures'
thing.each do |t|
t['photographer'] = photographer(t['photographer'])
end
end

if subject == 'photographers'
thing = thing.keys.map { |p| {'name' => p, 'website' => thing.dig(p, 'website') || {} }}
end
Expand Down
9 changes: 9 additions & 0 deletions spec/funkdata/photographers_data_spec.rb
Expand Up @@ -5,6 +5,15 @@ module Funkdata
expect(described_class.get_photographers).to be_an Array
expect(described_class.get_photographers.first['name']).to eq 'kim'
end

it 'gets a photographer', :vcr do
expect(described_class.photographer 'kim').to eq (
{
'name' => 'kim',
'website' => 'http://www.kimberlycabbott.com/'
}
)
end
end
end
end
6 changes: 6 additions & 0 deletions spec/funkdata/pictures_data_spec.rb
Expand Up @@ -4,6 +4,12 @@ module Funkdata
it 'lists the pictures', :vcr do
expect(described_class.get_pictures).to be_an Array
expect(described_class.get_pictures.first['date']).to eq '2015-07-06'
expect(described_class.get_pictures[1]['photographer']).to eq (
{
'name' => 'jane',
'website' => 'https://www.flickr.com/photos/cluttercup'
}
)
end
end
end
Expand Down

0 comments on commit b1448a2

Please sign in to comment.