unsplash_mango 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bc5b2262845511e8779726aadf311843c569052cbb2497fba3fe66f5c998a7d9
4
+ data.tar.gz: 67738b14f3607aa8ee57ba049138595a2d9c2ff9e89d0163b39f0f9bdd6d3d9e
5
+ SHA512:
6
+ metadata.gz: d313386a50198245e3d2632987cecb03aa573359a3d4dbe41934c9c62009263fd5c8e9f6bd2458d1d2dfcd8b8ad6ef61ef25106174c7d919ded5fe38ab5b11c3
7
+ data.tar.gz: 8cb31a9a3637789ce68c47091a18ff2b94673f5033b50a12fb99673a499bc5da5c0c92418b5dff42399d1c24b9a75277993a9991f18d795abc0489186f033b88
@@ -0,0 +1,17 @@
1
+ #### Steps to Reproduce
2
+
3
+ -
4
+
5
+ #### Observed Behaviour
6
+
7
+ -
8
+
9
+ > _Image or video please._
10
+
11
+ #### Expected Behaviour
12
+
13
+ -
14
+
15
+ #### Technical Notes
16
+
17
+ -
@@ -0,0 +1,12 @@
1
+ #### Overview
2
+
3
+ -
4
+ - Closes #
5
+
6
+ #### Todo
7
+
8
+ -
9
+
10
+ #### Screenshots/Videos (User Facing Changes)
11
+
12
+ > _Insert responsive image(s) and/or video(s)_
@@ -0,0 +1,13 @@
1
+ [
2
+ { "name": "Priority: Critical", "color": "#e11d21" },
3
+
4
+ { "name": "Status: Blocked", "color": "#e11d21" },
5
+ { "name": "Status: On Hold", "color": "#e11d21" },
6
+ { "name": "Status: In Progress", "color": "#fbca04" },
7
+ { "name": "Status: Ready for Review", "color": "#bfe5bf" },
8
+
9
+ { "name": "Type: Bug", "color": "#e11d21" },
10
+ { "name": "Type: Maintenance", "color": "#fbca04" },
11
+ { "name": "Type: Enhancement", "color": "#84b6eb" },
12
+ { "name": "Type: Question", "color": "#cc317c" }
13
+ ]
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.4.0
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.5
4
+ - 2.3.1
5
+ - 2.4.0
6
+ before_install: gem install bundler -v 1.10.2
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ --no-private
2
+ -
3
+ LICENSE.txt
4
+ CODE_OF_CONDUCT.md
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dev@unsplash.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in unsplash.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Aaron Klaassen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # unsplash_rb
2
+
3
+ [![Build Status](https://travis-ci.org/unsplash/unsplash_rb.svg?branch=travis)](https://travis-ci.org/unsplash/unsplash_rb)
4
+ [![Coverage Status](https://coveralls.io/repos/github/unsplash/unsplash_rb/badge.svg?branch=master&gh_cache_bust=1)](https://coveralls.io/github/unsplash/unsplash_rb?branch=master)
5
+
6
+ A ruby client for [the Unsplash API](https://unsplash.com/documentation).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'unsplash'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install unsplash
23
+
24
+ ## Usage
25
+
26
+ ### Configuration
27
+
28
+ Before making requests, you must configure the gem with your application ID
29
+ and secret. If you are using Rails, you can do this in an initializer.
30
+
31
+ ```ruby
32
+ Unsplash.configure do |config|
33
+ config.application_access_key = "YOUR ACCESS KEY"
34
+ config.application_secret = "YOUR APPLICATION SECRET"
35
+ config.application_redirect_uri = "https://your-application.com/oauth/callback"
36
+ config.utm_source = "alices_terrific_client_app"
37
+ end
38
+ ```
39
+
40
+ #### API Guidelines
41
+
42
+ All API applications must abide by the [API Guidelines](https://medium.com/unsplash/unsplash-api-guidelines-28e0216e6daa).
43
+
44
+ As part of [the API guidelines](https://medium.com/unsplash/unsplash-api-guidelines-28e0216e6daa), all API uses are required to use utm links when providing credit to photographers and Unsplash. Set the `config.utm_source` to your app's name to automatically append the utm source.
45
+
46
+ ### Public-scope actions
47
+
48
+ If you are *only* making public requests (i.e. nothing requiring a specific logged-in user, for example liking photos or accessing private user details), then you're ready to go!
49
+
50
+ Looking for details of a specific photo? Find it by ID:
51
+
52
+ ```ruby
53
+ photo = Unsplash::Photo.find("tAKXap853rY")
54
+ ```
55
+
56
+ Want a bunch of pictures of cats? You're on the internet; of course you do.
57
+
58
+ ```ruby
59
+ search_results = Unsplash::Photo.search("cats")
60
+ ```
61
+
62
+ For a complete list of available actions, see our [documentation details](http://www.rubydoc.info/github/unsplash/unsplash_rb/).
63
+
64
+ ### User Authorization
65
+
66
+ For non-public actions, you'll have to get the user's permission to access their data.
67
+ Direct them to the Unsplash authorization URL:
68
+
69
+ ```ruby
70
+ requested_scopes = ["public", "read_user", "something_else_you_are_asking_for"]
71
+ auth_url = Unsplash::Client.connection.authorization_url(requested_scopes)
72
+ ```
73
+
74
+ Upon authorization, Unsplash will return to you an authentication code via your OAuth
75
+ callback handler. With that you can generate an access token:
76
+
77
+ ```ruby
78
+ Unsplash::Client.connection.authorize!("the authentication code")
79
+ ```
80
+
81
+ And that's it. The API actions will be available to you according to whichever
82
+ permission scopes you requested and the user authorized.
83
+
84
+ ### Hotlinking
85
+
86
+ Hotlinking the [Unsplash image files is required](https://medium.com/@lukechesser/unsplash-api-guidelines-hotlinking-images-6c6b51030d2a)
87
+
88
+ Unlike most APIs, Unsplash requires for the image URLs returned by the API to be directly used or embedded in your applications (generally referred to as hotlinking). By using the CDN and embedding the photo URLs in your application, Unsplash can better track photo views and pass those stats on to the photographer, providing them with context for how popular their photo is and how it's being used.
89
+
90
+ ## Development
91
+
92
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
93
+
94
+ To install this gem onto your local machine, run `bundle exec rake install`.
95
+
96
+ ## Contributing
97
+
98
+ Bug reports and pull requests are welcome on GitHub at https://github.com/unsplash/unsplash_rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
99
+
100
+
101
+ ## License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
104
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "unsplash_mango"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ module Unsplash # :nodoc:
2
+
3
+ # Unsplash Category operations.
4
+ class Category < Client
5
+
6
+ class << self
7
+
8
+ # Get a list of all of the Unsplash photo categories.
9
+ # @return [Array] The list categories.
10
+ # <b>DEPRECATED</b>
11
+ def all
12
+ raise Unsplash::DeprecationError.new "Category has been deprecated and removed."
13
+ end
14
+
15
+ # Get an Unsplash Category.
16
+ # @param id [Integer] The ID of the category to retrieve.
17
+ # @return [Unsplash::Category] The specified category.
18
+ # <b>DEPRECATED</b>
19
+ def find(id)
20
+ raise Unsplash::DeprecationError.new "Category has been deprecated and removed."
21
+ end
22
+ end
23
+
24
+ # Get a list of all photos in this category.
25
+ # @param page [Integer] Which page of search results to return.
26
+ # @param per_page [Integer] The number of search results per page.
27
+ # @return [Array] A single page of +Unsplash::Photo+s.
28
+ # <b>DEPRECATED</b>
29
+ def photos(page = 1, per_page = 10)
30
+ raise Unsplash::DeprecationError.new "Category has been deprecated and removed."
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,57 @@
1
+ module Unsplash # :nodoc:
2
+
3
+ # Common functionality across Unsplash API objects.
4
+ class Client
5
+
6
+ # Build an Unsplash object with the given attributes.
7
+ # @param attrs [Hash]
8
+ def initialize(attrs = {})
9
+ @attributes = OpenStruct.new(attrs)
10
+ end
11
+
12
+ # (Re)load full object details from Unsplash.
13
+ # @return [Unspash::Client] Itself, with full details reloaded.
14
+ def reload!
15
+ if links && links["self"]
16
+ attrs = JSON.parse(connection.get(links["self"]).body)
17
+ @attributes = OpenStruct.new(attrs)
18
+ self
19
+ else
20
+ raise Unsplash::Error.new "Missing self link for #{self.class} with ID #{self.id}"
21
+ end
22
+ end
23
+
24
+ # Raw JSON as returned by Unsplash API.
25
+ # @return [Hash] json
26
+ def to_h
27
+ @attributes.to_h
28
+ end
29
+
30
+ # @private
31
+ def method_missing(method, *args, &block)
32
+ attribute = @attributes.send(method, *args, &block)
33
+ attribute.is_a?(Hash) ? Client.new(attribute) : attribute
34
+ end
35
+
36
+ # The connection object being used to communicate with Unsplash.
37
+ # @return [Unsplash::Connection] the connection
38
+ def connection
39
+ self.class.connection
40
+ end
41
+
42
+ class << self
43
+ # The connection object being used to communicate with Unsplash.
44
+ # @return [Unsplash::Connection] the connection
45
+ def connection
46
+ @@connection ||= Connection.new
47
+ end
48
+
49
+ # Assign a default connection object.
50
+ # @param conn [Unsplash::Connection] the connection
51
+ # @return [Unsplash::Connection] the connection
52
+ def connection=(conn)
53
+ @@connection = conn
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,152 @@
1
+ module Unsplash # :nodoc:
2
+
3
+ # Unsplash Collection operations.
4
+ class Collection < Client
5
+
6
+ class << self
7
+
8
+ # Get a specific collection.
9
+ # @param id [Integer] The ID of the collection.
10
+ # @return [Unsplash::Collection] The requested collection.
11
+ def find(id, curated = false)
12
+ url = ["/collections", (curated ? "curated" : nil), id].compact.join("/")
13
+ Unsplash::Collection.new JSON.parse(connection.get(url).body)
14
+ end
15
+
16
+ # Get a list of all collections.
17
+ # @param page [Integer] Which page of search results to return.
18
+ # @param per_page [Integer] The number of search results per page. (default: 10, maximum: 30)
19
+ # @return [Array] A single page of the +Unsplash::Collection+ list.
20
+ def all(page = 1, per_page = 10)
21
+ params = {
22
+ page: page,
23
+ per_page: per_page
24
+ }
25
+ list = JSON.parse(connection.get("/collections/", params).body)
26
+ list.map { |data| Unsplash::Collection.new(data) }
27
+ end
28
+
29
+
30
+ # Get a list of all featured collections.
31
+ # @param page [Integer] Which page of results to return.
32
+ # @param per_page [Integer] The number of results per page. (default: 10, maximum: 30)
33
+ # @return [Array] A single page of the +Unsplash::Collection+ list.
34
+ def featured(page = 1, per_page = 10)
35
+ params = {
36
+ page: page,
37
+ per_page: per_page
38
+ }
39
+ list = JSON.parse(connection.get("/collections/featured", params).body)
40
+ list.map { |data| Unsplash::Collection.new(data) }
41
+ end
42
+
43
+ # Get a list of all curated collections.
44
+ # @param page [Integer] Which page of search results to return.
45
+ # @param per_page [Integer] The number of search results per page. (default: 10, maximum: 30)
46
+ # @return [Array] A single page of the +Unsplash::Collection+ list.
47
+ def curated(page = 1, per_page = 10)
48
+ params = {
49
+ page: page,
50
+ per_page: per_page
51
+ }
52
+ list = JSON.parse(connection.get("/collections/curated", params).body)
53
+ list.map { |data| Unsplash::Collection.new(data) }
54
+ end
55
+
56
+ # Create a new collection on behalf of current user.
57
+ # @param title [String] The title of the collection.
58
+ # @param description [String] The collection's description. (optional)
59
+ # @param private [Boolean] Whether to make the collection private. (optional, default +false+)
60
+ def create(title: "", description: "", private: false)
61
+ params = {
62
+ title: title,
63
+ description: description,
64
+ private: private
65
+ }
66
+ Unsplash::Collection.new JSON.parse(connection.post("/collections", params).body)
67
+ end
68
+
69
+ # Get a single page of collection results for a query.
70
+ # @param query [String] Keywords to search for.
71
+ # @param page [Integer] Which page of search results to return.
72
+ # @param per_page [Integer] The number of collections search result per page. (default: 10, maximum: 30)
73
+ # @return [SearchResult] a list of +Unsplash::Collection+ objects.
74
+ def search(query, page = 1, per_page = 10)
75
+ params = {
76
+ query: query,
77
+ page: page,
78
+ per_page: per_page
79
+ }
80
+ Unsplash::Search.search("/search/collections", self, params)
81
+ end
82
+
83
+ end
84
+
85
+ def initialize(options = {})
86
+ options["user"] = Unsplash::User.new options["user"]
87
+ options["cover_photo"] = Unsplash::Photo.new options["cover_photo"]
88
+ super(options)
89
+ end
90
+
91
+ # Update the collection's attributes.
92
+ # @param title [String] The title of the collection.
93
+ # @param description [String] The collection's description. (optional)
94
+ # @param private [Boolean] Whether to make the collection private. (optional)
95
+ def update(title: nil, description: nil, private: nil)
96
+ params = {
97
+ title: title,
98
+ description: description,
99
+ private: private
100
+ }.select { |k,v| v }
101
+ updated = JSON.parse(connection.put("/collections/#{id}", params).body)
102
+ self.title = updated["title"]
103
+ self.description = updated["description"]
104
+ self
105
+ end
106
+
107
+ # Delete the collection. This does not delete the photos it contains.
108
+ # @return [Boolean] +true+ on success.
109
+ def destroy
110
+ response = connection.delete("/collections/#{id}")
111
+ (200..299).include?(response.status)
112
+ end
113
+
114
+ # Get a list of the photos contained in this collection.
115
+ # @param page [Integer] Which page of photos collection to return.
116
+ # @param per_page [Integer] The number of photos per page. (default: 10, maximum: 30)
117
+ # @return [Array] The list of +Unsplash::Photo+s in the collection.
118
+ def photos(page = 1, per_page = 10)
119
+ params = {
120
+ page: page,
121
+ per_page: per_page
122
+ }
123
+
124
+ list = JSON.parse(connection.get("/collections/#{id}/photos", params).body)
125
+ list.map { |photo| Unsplash::Photo.new photo }
126
+ end
127
+
128
+ # Add a photo to the collection. If the photo is already in the collection,
129
+ # this action has no effect.
130
+ # @param [Unsplash::Photo] The photo to add.
131
+ # @return [Hash] Collected photo metadata.
132
+ def add(photo)
133
+ response = JSON.parse(connection.post("/collections/#{id}/add", { photo_id: photo.id }).body)
134
+ {
135
+ photo_id: response["photo"]["id"],
136
+ collection_id: response["collection"]["id"],
137
+ user_id: response["user"]["id"],
138
+ created_at: response["created_at"]
139
+ }
140
+ end
141
+
142
+ # Remove a photo from the collection. If the photo is not in the collection,
143
+ # this action has no effect.
144
+ # @param [Unsplash::Photo] The photo to remove.
145
+ # @return [Boolean] +true+ on success.
146
+ def remove(photo)
147
+ response = connection.delete("/collections/#{id}/remove", photo_id: photo.id)
148
+ (200..299).include?(response.status)
149
+ end
150
+
151
+ end
152
+ end