pexels_api_client 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.gitlab-ci.yml +15 -0
- data/.rspec +1 -0
- data/.rubocop.yml +29 -0
- data/.travis.yml +7 -0
- data/CHANGELOG +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +126 -0
- data/LICENSE.txt +21 -0
- data/README.md +165 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/pexels_api_client.rb +22 -0
- data/lib/pexels_api_client/base.rb +19 -0
- data/lib/pexels_api_client/config.rb +40 -0
- data/lib/pexels_api_client/errors.rb +9 -0
- data/lib/pexels_api_client/photo.rb +10 -0
- data/lib/pexels_api_client/version.rb +5 -0
- data/lib/pexels_api_client/video.rb +10 -0
- data/pexels_api_client.gemspec +47 -0
- metadata +250 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7c5716d9529fecdda2007e2b10d2df7e7ed7b82a684121a799fdc69de901e378
|
4
|
+
data.tar.gz: 1dde10f99eac937ca3c13fe6aa5657056ce43fc23438bbb9e9c97aadfd9dc697
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b4e3ab21a72855d4a42575ef7351b67db548a660220023e629ec993b7c82f1e21329f4af5f404f3696a60a87b5acf6c537653499ce848877e6c2f837435b909
|
7
|
+
data.tar.gz: f3f8f054bfd7eed6bfe650e9cdabe63911127aeb6c830b9879079894eeff2027821e310681cf0e9383f0517dad4766bb7cecd6d59e9fba1ae23c2a0a1d9d14cf
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6.3
|
3
|
+
|
4
|
+
Style/Documentation:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/LineLength:
|
8
|
+
Max: 190
|
9
|
+
|
10
|
+
Style/HashSyntax:
|
11
|
+
EnforcedStyle: ruby19
|
12
|
+
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Exclude:
|
15
|
+
- 'spec/**/*'
|
16
|
+
- 'spec/support/fake_pexels.rb'
|
17
|
+
- 'pexels_api_client.gemspec'
|
18
|
+
|
19
|
+
Metrics/BlockLength:
|
20
|
+
Exclude:
|
21
|
+
- 'spec/**/*'
|
22
|
+
- 'spec/support/fake_pexels.rb'
|
23
|
+
- 'pexels_api_client.gemspec'
|
24
|
+
|
25
|
+
Metrics/ClassLength:
|
26
|
+
Exclude:
|
27
|
+
- 'spec/**/*'
|
28
|
+
- 'spec/support/fake_pexels.rb'
|
29
|
+
- 'pexels_api_client.gemspec'
|
data/.travis.yml
ADDED
data/CHANGELOG
ADDED
File without changes
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 noragmora@gmail.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
data/Gemfile.lock
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pexels_api_client (0.1.2)
|
5
|
+
activesupport
|
6
|
+
api-auth (~> 2.3.1)
|
7
|
+
flexirest (~> 1.8.6)
|
8
|
+
json (~> 2.2.0)
|
9
|
+
rest-client (~> 2.1.0)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
activesupport (6.0.1)
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
i18n (>= 0.7, < 2)
|
17
|
+
minitest (~> 5.1)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
zeitwerk (~> 2.2)
|
20
|
+
addressable (2.7.0)
|
21
|
+
public_suffix (>= 2.0.2, < 5.0)
|
22
|
+
api-auth (2.3.1)
|
23
|
+
ast (2.4.0)
|
24
|
+
bump (0.8.0)
|
25
|
+
concurrent-ruby (1.1.5)
|
26
|
+
crack (0.4.3)
|
27
|
+
safe_yaml (~> 1.0.0)
|
28
|
+
diff-lcs (1.3)
|
29
|
+
domain_name (0.5.20190701)
|
30
|
+
unf (>= 0.0.5, < 1.0.0)
|
31
|
+
faraday (0.17.1)
|
32
|
+
multipart-post (>= 1.2, < 3)
|
33
|
+
flexirest (1.8.6)
|
34
|
+
activesupport
|
35
|
+
crack
|
36
|
+
faraday
|
37
|
+
mime-types
|
38
|
+
multi_json
|
39
|
+
hashdiff (1.0.0)
|
40
|
+
http-accept (1.7.0)
|
41
|
+
http-cookie (1.0.3)
|
42
|
+
domain_name (~> 0.5)
|
43
|
+
i18n (1.7.0)
|
44
|
+
concurrent-ruby (~> 1.0)
|
45
|
+
jaro_winkler (1.5.4)
|
46
|
+
json (2.2.0)
|
47
|
+
mime-types (3.3)
|
48
|
+
mime-types-data (~> 3.2015)
|
49
|
+
mime-types-data (3.2019.1009)
|
50
|
+
minitest (5.13.0)
|
51
|
+
multi_json (1.14.1)
|
52
|
+
multipart-post (2.1.1)
|
53
|
+
mustermann (1.0.3)
|
54
|
+
netrc (0.11.0)
|
55
|
+
parallel (1.19.1)
|
56
|
+
parser (2.6.5.0)
|
57
|
+
ast (~> 2.4.0)
|
58
|
+
public_suffix (4.0.1)
|
59
|
+
rack (2.0.7)
|
60
|
+
rack-protection (2.0.7)
|
61
|
+
rack
|
62
|
+
rainbow (3.0.0)
|
63
|
+
rake (10.5.0)
|
64
|
+
rest-client (2.1.0)
|
65
|
+
http-accept (>= 1.7.0, < 2.0)
|
66
|
+
http-cookie (>= 1.0.2, < 2.0)
|
67
|
+
mime-types (>= 1.16, < 4.0)
|
68
|
+
netrc (~> 0.8)
|
69
|
+
rspec (3.9.0)
|
70
|
+
rspec-core (~> 3.9.0)
|
71
|
+
rspec-expectations (~> 3.9.0)
|
72
|
+
rspec-mocks (~> 3.9.0)
|
73
|
+
rspec-core (3.9.0)
|
74
|
+
rspec-support (~> 3.9.0)
|
75
|
+
rspec-expectations (3.9.0)
|
76
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
77
|
+
rspec-support (~> 3.9.0)
|
78
|
+
rspec-mocks (3.9.0)
|
79
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
80
|
+
rspec-support (~> 3.9.0)
|
81
|
+
rspec-support (3.9.0)
|
82
|
+
rubocop (0.77.0)
|
83
|
+
jaro_winkler (~> 1.5.1)
|
84
|
+
parallel (~> 1.10)
|
85
|
+
parser (>= 2.6)
|
86
|
+
rainbow (>= 2.2.2, < 4.0)
|
87
|
+
ruby-progressbar (~> 1.7)
|
88
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
89
|
+
ruby-progressbar (1.10.1)
|
90
|
+
safe_yaml (1.0.5)
|
91
|
+
sinatra (2.0.7)
|
92
|
+
mustermann (~> 1.0)
|
93
|
+
rack (~> 2.0)
|
94
|
+
rack-protection (= 2.0.7)
|
95
|
+
tilt (~> 2.0)
|
96
|
+
thread_safe (0.3.6)
|
97
|
+
tilt (2.0.10)
|
98
|
+
tzinfo (1.2.5)
|
99
|
+
thread_safe (~> 0.1)
|
100
|
+
unf (0.1.4)
|
101
|
+
unf_ext
|
102
|
+
unf_ext (0.0.7.6)
|
103
|
+
unicode-display_width (1.6.0)
|
104
|
+
vcr (5.0.0)
|
105
|
+
webmock (3.7.6)
|
106
|
+
addressable (>= 2.3.6)
|
107
|
+
crack (>= 0.3.2)
|
108
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
109
|
+
zeitwerk (2.2.2)
|
110
|
+
|
111
|
+
PLATFORMS
|
112
|
+
ruby
|
113
|
+
|
114
|
+
DEPENDENCIES
|
115
|
+
bump (~> 0.8.0)
|
116
|
+
bundler (~> 2.0)
|
117
|
+
pexels_api_client!
|
118
|
+
rake (~> 10.0)
|
119
|
+
rspec (~> 3.9.0)
|
120
|
+
rubocop (~> 0.77.0)
|
121
|
+
sinatra (~> 2.0.7)
|
122
|
+
vcr (~> 5.0.0)
|
123
|
+
webmock (~> 3.7.6)
|
124
|
+
|
125
|
+
BUNDLED WITH
|
126
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Nora Gabriela Alvarado
|
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,165 @@
|
|
1
|
+
# PexelsApiClient
|
2
|
+
|
3
|
+
PexelsApiClient its a Ruby wrapper for the [Pexels](https://www.pexels.com) API. Please read Pexel's [documentation](https://www.pexels.com/api/documentation/) on how to start using their API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pexels_api_client'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pexels_api_client
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To start using the Pexel's API you'll first need to setup an [account](https://www.pexels.com/join/) on their site, once you have an account you will need to request an [Api Key](https://www.pexels.com/api/new/)
|
24
|
+
|
25
|
+
Now you can configure the gem with:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
PexelsApiClient.config do |config|
|
29
|
+
config.api_key = '<API_KEY>'
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
#### Photo Methods
|
34
|
+
|
35
|
+
* **Find**: If you have the id of a photo, you can retrieve the data of it.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
photo = PexelsApiClient::Photo.find(id)
|
39
|
+
photo.width # => 1400
|
40
|
+
photo.photographer # => John Doe
|
41
|
+
# ...
|
42
|
+
```
|
43
|
+
|
44
|
+
* **Curated**: Get a Curated list of trending photos.
|
45
|
+
|
46
|
+
| **options** | |
|
47
|
+
| ------ | ------ |
|
48
|
+
| per_page | Defines the number of results per page. (optional, default: 15, max: 80) |
|
49
|
+
| page | Defines the number of the page. (optional, default: 1) |
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
curated_photos = PexelsApiClient::Photo.curated # => Fallback to default options
|
53
|
+
-- or --
|
54
|
+
curated_photos = PexelsApiClient::Photo.curated(per_page: 5, page: 2) # => With custom options
|
55
|
+
|
56
|
+
curated_photos.photos # => [photo1, photo2,etc]
|
57
|
+
curated_photos.photos.first.photographer # => John Doe
|
58
|
+
# ...
|
59
|
+
```
|
60
|
+
|
61
|
+
* **Random**: Returns a random photo from the curated photos
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
random_photo = PexelsApiClient::Photo.random
|
65
|
+
|
66
|
+
random_photo.photos # => [photo1]
|
67
|
+
random_photo.photos.first.photographer # => John Doe
|
68
|
+
# ...
|
69
|
+
```
|
70
|
+
|
71
|
+
* **Search**: Search for photos related to a query
|
72
|
+
|
73
|
+
| **options** | |
|
74
|
+
| ------ | ------ |
|
75
|
+
| query | Get photos related to this query. (required) |
|
76
|
+
| per_page | Defines the number of results per page. (optional, default: 15, max: 80) |
|
77
|
+
| page | Defines the number of the page. (optional, default: 1) |
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
search_photos = PexelsApiClient::Photo.search(per_page: 5, page: 2, query: 'people')
|
81
|
+
|
82
|
+
curated_photos.photos # => [photo1, photo2,etc]
|
83
|
+
curated_photos.photos.first.photographer # => John Doe
|
84
|
+
# ...
|
85
|
+
```
|
86
|
+
|
87
|
+
#### Video Methods
|
88
|
+
|
89
|
+
* **Find**: If you have the id of a video, you can retrieve the data of it.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
video = PexelsApiClient::Video.find(id)
|
93
|
+
video.width # => 1400
|
94
|
+
video.user.name # => John Doe
|
95
|
+
# ...
|
96
|
+
```
|
97
|
+
|
98
|
+
* **Popular**: Get a list of popular videos.
|
99
|
+
|
100
|
+
| **options** | |
|
101
|
+
| ------ | ------ |
|
102
|
+
| per_page | Defines the number of results per page. (optional, default: 15, max: 80) |
|
103
|
+
| page | Defines the number of the page. (optional, default: 1) |
|
104
|
+
| min_width | The minimum width in pixels of the returned videos. (optional, default: "") |
|
105
|
+
| max_width | The maximum width in pixels of the returned videos. (optional, default: "") |
|
106
|
+
| min_duration | The minimum duration in seconds of the returned videos. (optional, default: "")|
|
107
|
+
| max_duration | The maximum duration in seconds of the returned videos. (optional, default: "") |
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
popular_videos = PexelsApiClient::Video.popular # => Fallback to default options
|
111
|
+
-- or --
|
112
|
+
popular_videos = PexelsApiClient::Video.popular(per_page: 5, page: 2) # => With custom options
|
113
|
+
|
114
|
+
popular_videos.videos # => [video1, video2, etc]
|
115
|
+
popular_videos.videos.first.user.name # => John Doe
|
116
|
+
# ...
|
117
|
+
```
|
118
|
+
|
119
|
+
* **Random**: Returns a random video from the popular videos
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
random_video = PexelsApiClient::Video.random
|
123
|
+
|
124
|
+
random_video.videos # => [photo1]
|
125
|
+
random_video.videos.first.user.name # => John Doe
|
126
|
+
# ...
|
127
|
+
```
|
128
|
+
|
129
|
+
* **Search**: Search for videos related to a query
|
130
|
+
|
131
|
+
| **options** | |
|
132
|
+
| ------ | ------ |
|
133
|
+
| query | Get videos related to this query. (required) |
|
134
|
+
| per_page | Defines the number of results per page. (optional, default: 15, max: 80) |
|
135
|
+
| page | Defines the number of the page. (optional, default: 1) |
|
136
|
+
| min_width | The minimum width in pixels of the returned videos. (optional, default: "") |
|
137
|
+
| max_width | The maximum width in pixels of the returned videos. (optional, default: "") |
|
138
|
+
| min_duration | The minimum duration in seconds of the returned videos. (optional, default: "")|
|
139
|
+
| max_duration | The maximum duration in seconds of the returned videos. (optional, default: "") |
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
search_videos = PexelsApiClient::Video.search(per_page: 5, page: 2, query: 'people')
|
143
|
+
|
144
|
+
search_videos.videos # => [video1, video2,etc]
|
145
|
+
search_videos.videos.first.user.name # => John Doe
|
146
|
+
# ...
|
147
|
+
```
|
148
|
+
|
149
|
+
## Development
|
150
|
+
|
151
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
152
|
+
|
153
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
154
|
+
|
155
|
+
## Contributing
|
156
|
+
|
157
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pexels_api_client. 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.
|
158
|
+
|
159
|
+
## License
|
160
|
+
|
161
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
162
|
+
|
163
|
+
## Code of Conduct
|
164
|
+
|
165
|
+
Everyone interacting in the PexelsApiClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](http://contributor-covenant.org)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'pexels_api_client'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'flexirest'
|
4
|
+
|
5
|
+
module PexelsApiClient
|
6
|
+
require 'pexels_api_client/errors'
|
7
|
+
|
8
|
+
autoload :Base, 'pexels_api_client/base'
|
9
|
+
autoload :Photo, 'pexels_api_client/photo'
|
10
|
+
autoload :Video, 'pexels_api_client/video'
|
11
|
+
autoload :Config, 'pexels_api_client/config'
|
12
|
+
|
13
|
+
BASE_URL = 'https://api.pexels.com/'
|
14
|
+
|
15
|
+
def self.config
|
16
|
+
if block_given?
|
17
|
+
yield(PexelsApiClient::Config)
|
18
|
+
else
|
19
|
+
PexelsApiClient::Config
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rest-client'
|
4
|
+
|
5
|
+
module PexelsApiClient
|
6
|
+
class Base < Flexirest::Base
|
7
|
+
after_request :rescue_errors
|
8
|
+
|
9
|
+
def rescue_errors(_name, response)
|
10
|
+
if (400..499).cover?(response.status)
|
11
|
+
result = JSON.parse(response.body)
|
12
|
+
message = result['errors'] || [result['error']]
|
13
|
+
raise BadRequestError, message.to_a.join(', ')
|
14
|
+
elsif (500..599).cover?(response.status)
|
15
|
+
raise ServerError, "Could not process your request: status #{response.status}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PexelsApiClient
|
4
|
+
module Config
|
5
|
+
class << self
|
6
|
+
attr_reader :api_key, :base_url
|
7
|
+
|
8
|
+
def reset
|
9
|
+
@api_key = nil
|
10
|
+
@base_url = PexelsApiClient::BASE_URL
|
11
|
+
end
|
12
|
+
|
13
|
+
def api_key=(api_key)
|
14
|
+
@api_key = api_key
|
15
|
+
set_api_auth
|
16
|
+
end
|
17
|
+
|
18
|
+
def base_url=(base_url)
|
19
|
+
@base_url = base_url
|
20
|
+
set_api_auth
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def set_api_auth
|
26
|
+
Flexirest::Base.base_url = base_url
|
27
|
+
Flexirest::Base.request_body_type = :json
|
28
|
+
|
29
|
+
Flexirest::Base.faraday_config do |faraday|
|
30
|
+
faraday.adapter(:net_http)
|
31
|
+
faraday.options.timeout = 10
|
32
|
+
faraday.headers['User-Agent'] = "Flexirest/#{Flexirest::VERSION}"
|
33
|
+
faraday.headers['Authorization'] = @api_key
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
reset
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PexelsApiClient
|
4
|
+
PexelsApiClientError = Class.new StandardError
|
5
|
+
BadRequestError = Class.new StandardError
|
6
|
+
ServerError = Class.new StandardError
|
7
|
+
ApiKeyError = Class.new StandardError
|
8
|
+
NotApiKeyError = Class.new ArgumentError
|
9
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PexelsApiClient
|
4
|
+
class Photo < PexelsApiClient::Base
|
5
|
+
get :curated, 'v1/curated', defaults: { per_page: 15, page: 1 }
|
6
|
+
get :random, 'v1/curated', defaults: { per_page: 1, page: rand(1..1000) }
|
7
|
+
get :search, 'v1/search', defaults: { per_page: 15, page: 1 }, required: [:query]
|
8
|
+
get :find, 'v1/photos/:id'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PexelsApiClient
|
4
|
+
class Video < PexelsApiClient::Base
|
5
|
+
get :find, 'videos/videos/:id'
|
6
|
+
get :popular, 'videos/popular', defaults: { per_page: 15, page: 1, min_width: '', max_width: '', min_duration: '', max_duration: '' }
|
7
|
+
get :random, 'videos/popular', defaults: { per_page: 1, page: rand(1..1000), min_width: '', max_width: '', min_duration: '', max_duration: '' }
|
8
|
+
get :search, 'videos/search', defaults: { per_page: 15, page: 1, min_width: '', max_width: '', min_duration: '', max_duration: '' }, required: [:query]
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'pexels_api_client/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'pexels_api_client'
|
9
|
+
spec.version = PexelsApiClient::VERSION
|
10
|
+
spec.authors = ['Nora Gabriela Alvarado']
|
11
|
+
spec.email = ['noragmora@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'This gem is used to access the Pexels API.'
|
14
|
+
spec.description = 'Using this gem allows you to make requests to the Pexels API endpoints.'
|
15
|
+
spec.homepage = 'https://gitlab.com/aromaron/pexels_api_client'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = 'https://gitlab.com/aromaron/pexels_api_client'
|
20
|
+
spec.metadata['changelog_uri'] = 'https://gitlab.com/aromaron/pexels_api_client/blob/master/CHANGELOG'
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
spec.required_ruby_version = '~> 2.6.3'
|
32
|
+
|
33
|
+
spec.add_runtime_dependency 'activesupport'
|
34
|
+
spec.add_runtime_dependency 'api-auth', '~> 2.3.1'
|
35
|
+
spec.add_runtime_dependency 'flexirest', '~> 1.8.6'
|
36
|
+
spec.add_runtime_dependency 'json', '~> 2.2.0'
|
37
|
+
spec.add_runtime_dependency 'rest-client', '~> 2.1.0'
|
38
|
+
|
39
|
+
spec.add_development_dependency 'bump', '~> 0.8.0'
|
40
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
41
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
42
|
+
spec.add_development_dependency 'rspec', '~> 3.9.0'
|
43
|
+
spec.add_development_dependency 'rubocop', '~> 0.77.0'
|
44
|
+
spec.add_development_dependency 'sinatra', '~> 2.0.7'
|
45
|
+
spec.add_development_dependency 'vcr', '~> 5.0.0'
|
46
|
+
spec.add_development_dependency 'webmock', '~> 3.7.6'
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,250 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pexels_api_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nora Gabriela Alvarado
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: api-auth
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.3.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.3.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: flexirest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.8.6
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.6
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.1.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.1.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bump
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.8.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.8.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.9.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.9.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.77.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.77.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sinatra
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 2.0.7
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 2.0.7
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: vcr
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 5.0.0
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 5.0.0
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: webmock
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 3.7.6
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 3.7.6
|
195
|
+
description: Using this gem allows you to make requests to the Pexels API endpoints.
|
196
|
+
email:
|
197
|
+
- noragmora@gmail.com
|
198
|
+
executables: []
|
199
|
+
extensions: []
|
200
|
+
extra_rdoc_files: []
|
201
|
+
files:
|
202
|
+
- ".gitignore"
|
203
|
+
- ".gitlab-ci.yml"
|
204
|
+
- ".rspec"
|
205
|
+
- ".rubocop.yml"
|
206
|
+
- ".travis.yml"
|
207
|
+
- CHANGELOG
|
208
|
+
- CODE_OF_CONDUCT.md
|
209
|
+
- Gemfile
|
210
|
+
- Gemfile.lock
|
211
|
+
- LICENSE.txt
|
212
|
+
- README.md
|
213
|
+
- Rakefile
|
214
|
+
- bin/console
|
215
|
+
- bin/setup
|
216
|
+
- lib/pexels_api_client.rb
|
217
|
+
- lib/pexels_api_client/base.rb
|
218
|
+
- lib/pexels_api_client/config.rb
|
219
|
+
- lib/pexels_api_client/errors.rb
|
220
|
+
- lib/pexels_api_client/photo.rb
|
221
|
+
- lib/pexels_api_client/version.rb
|
222
|
+
- lib/pexels_api_client/video.rb
|
223
|
+
- pexels_api_client.gemspec
|
224
|
+
homepage: https://gitlab.com/aromaron/pexels_api_client
|
225
|
+
licenses:
|
226
|
+
- MIT
|
227
|
+
metadata:
|
228
|
+
homepage_uri: https://gitlab.com/aromaron/pexels_api_client
|
229
|
+
source_code_uri: https://gitlab.com/aromaron/pexels_api_client
|
230
|
+
changelog_uri: https://gitlab.com/aromaron/pexels_api_client/blob/master/CHANGELOG
|
231
|
+
post_install_message:
|
232
|
+
rdoc_options: []
|
233
|
+
require_paths:
|
234
|
+
- lib
|
235
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
236
|
+
requirements:
|
237
|
+
- - "~>"
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: 2.6.3
|
240
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
241
|
+
requirements:
|
242
|
+
- - ">="
|
243
|
+
- !ruby/object:Gem::Version
|
244
|
+
version: '0'
|
245
|
+
requirements: []
|
246
|
+
rubygems_version: 3.0.3
|
247
|
+
signing_key:
|
248
|
+
specification_version: 4
|
249
|
+
summary: This gem is used to access the Pexels API.
|
250
|
+
test_files: []
|