PastVu
PastVu gem is a Ruby wrapper for PastVu API. It allows convenient interaction with the API in your Ruby code.
PastVu is an open-source online platform for gathering, geo-tagging, attributing and discussing retro photos. Its repository can be found on GitHub.
Installation
Install the gem and add to the application's Gemfile by executing:
$ bundle add pastvu
or add the following line to the Gemfile manually
# gem "pastvu"
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install pastvu
and do not forget to require the gem in your code:
require "pastvu"
Usage
Refer to PastVu API documentation for available interactions, parameters, parameter types and response examples.
Scenario: Getting nearest photos
Step one - request data
golden_gate_coordinates = [37.82,-122.469322]
photo_collection = Pastvu.nearest_photos(geo: golden_gate_coordinates)
photo_collection = Pastvu.nearest_photos(
geo: golden_gate_coordinates,
except: 228481,
limit: 12
)
new_photo_collection = photo_collection.next
new_photo_collection = photo_collection.next(5)
Step two - work with data
Manipulate attributes:
photo_collection.to_json
photo_collection.to_hash
photo_collection.each do |photo|
puts photo.title
puts photo.year
puts photo.geo
hash = photo.to_hash
puts hash["title"]
puts hash["year"]
puts hash["geo"]
photo.to_json
end
Download photos:
photo_collection.each_with_index do |photo, i|
photo.standard
photo.original
photo.thumb
desired_path_to_photo = "awesome_photo_number_#{i + 1}.jpg"
photo.download(:standard, desired_path_to_photo)
photo.download(:original, desired_path_to_photo)
photo.download(:thumb, desired_path_to_photo)
end
Request more data about the photo:
photo_collection.each do |photo|
photo.comments
photo.reload
end
Scenario: Getting photos inside geographical bounds
Step one - prepare request
PastVu API accepts geoJSON polygons and geoJSON multipolygons
paris_montmartre = '{"coordinates":[[[2.34218629483172,48.88623415508624],[2.34218629483172,48.88425956838617],[2.3449771858020085,48.88425956838617],[2.3449771858020085,48.88623415508624],[2.34218629483172,48.88623415508624]]],"type":"Polygon"}'
paris_montmartre = {
"type" => "Polygon",
"coordinates" => [
[
[
2.34218629483172,
48.88623415508624
],
[
2.34218629483172,
48.88425956838617
],
[
2.3449771858020085,
48.88425956838617
],
[
2.3449771858020085,
48.88623415508624
],
[
2.34218629483172,
48.88623415508624
]
]
]
}
Step two - request data
bounds_response = Pastvu.by_bounds(
geometry: paris_montmartre,
z: 16
)
The response may contain clusters, photos, or both - see API docs
photo_collection = bounds_response.photos
cluster_collection = bounds_response.clusters
Step three - manipulate data
Photos
PhotoCollection and each photo object have almost all the same methods as discussed in the previous scenario section.
Note that PastVu API may send different photo data for by_bounds and nearest_photos requests. This, however, does not obstruct in-built convenience methods for downloading.
For instance:
photo_collection.each do |photo|
photo.original
photo.year2
end
photo_collection.next
Clusters
On the Pastvu website, clusters are representations of multiple photos. Users see clusters when zooming out.
cluster_collection.to_json
cluster_collection.to_hash
cluster_collection.each do |cluster|
puts cluster.c
hash = cluster.to_hash
puts hash["c"]
cluster.to_json
cluster.photo
end
Scenario: Getting full photo information
photo_cid = 5
photo_information = Pastvu.photo_info(photo_cid)
photo_information.to_json
photo_information.to_hash
photo = photo_information.to_photo
photo = Pastvu.photo(photo_cid)
The created Photo object will respond to all the methods discussed previously but it tends to have more attributes. Finally, it is possible to request full information for any Photo object by calling Photo#reload
on Photo instance, which returns a new Photo instance.
photo_cid = 5
comment_collection = Pastvu.comments(photo_cid)
comment_collection.users
comment_collection.each do |comment|
puts cluster.user
puts cluster.txt
hash = cluster.to_hash
puts hash["user"]
puts hash["txt"]
cluster.to_json
comment.replies
end
Configuration
Pastvu.configure do |c|
c.host
c.path
c.user_agent
c.ensure_successful_responses
c.check_params_type
c.check_params_value
end
To do list
- Rework tests to use VCR gem
- Refactor tests
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/projecteurlumiere/pastvu.
License
The gem is available as open source under the terms of the MIT License.