rails-pinterest 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dfa618448e8b37a33626256d665db18ddb5f14aedf33649cbd94e26cde93ad74
4
+ data.tar.gz: 4f837c35d9a9643f0ef4217bad93e74e09dbb0d982a1a2aafad0730bf55a01f8
5
+ SHA512:
6
+ metadata.gz: 591845e43604e43211fa83ca1a5695b2356ee4429729f4c8cda66f6509abc331951f7a6370f1601a668c6e5f88757a9416601ef542456e494fbacb0a6c995016
7
+ data.tar.gz: 67c594c47da7f9abe31c828d4d880ce21727514f77f3a56b006a4386406720f0942de778100c83d4a9db43a0b5a7a7b9618d76db821fac4f0cf0e845c21488fd
data/.gitignore ADDED
@@ -0,0 +1,74 @@
1
+ ### Ruby ###
2
+ *.gem
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+ /.bundle/
14
+ /.yardoc
15
+ /_yardoc/
16
+ /doc/
17
+
18
+
19
+ # Used by dotenv library to load environment variables.
20
+ .env
21
+
22
+ # Ignore Byebug command history file.
23
+ .byebug_history
24
+
25
+ ## Specific to RubyMotion:
26
+ .dat*
27
+ .repl_history
28
+ build/
29
+ *.bridgesupport
30
+ build-iPhoneOS/
31
+ build-iPhoneSimulator/
32
+
33
+ ## Specific to RubyMotion (use of CocoaPods):
34
+ #
35
+ # We recommend against adding the Pods directory to your .gitignore. However
36
+ # you should judge for yourself, the pros and cons are mentioned at:
37
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
38
+ # vendor/Pods/
39
+
40
+ ## Documentation cache and generated files:
41
+ /.yardoc/
42
+ /_yardoc/
43
+ /doc/
44
+ /rdoc/
45
+
46
+ ## Environment normalization:
47
+ /.bundle/
48
+ /vendor/bundle
49
+ /lib/bundler/man/
50
+
51
+ # for a library or gem, you might want to ignore these files since the code is
52
+ # intended to run in multiple environments; otherwise, check them in:
53
+ # Gemfile.lock
54
+ # .ruby-version
55
+ # .ruby-gemset
56
+
57
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
58
+ .rvmrc
59
+
60
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
61
+ # .rubocop-https?--*
62
+
63
+ # rspec failure tracking
64
+ .rspec_status
65
+
66
+ # IDE
67
+ .idea
68
+ .idea/
69
+ .idea/*
70
+ .vscode
71
+ .vs/
72
+
73
+ # Mac
74
+ .DS_Store
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-10-01
4
+
5
+ - Initial release
6
+ - Endpoints for Pins and Boards created
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at donaldlee50@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ruby-leonardoai.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "byebug", "~> 11.1.3"
10
+ gem "dotenv", "~> 2.8.1"
11
+ gem "rspec", "~> 3.12"
12
+ gem "rubocop", "~> 1.50.2"
13
+ gem "vcr", "~> 6.1.0"
14
+ gem "webmock", "~> 3.18.1"
data/Gemfile.lock ADDED
@@ -0,0 +1,88 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails-pinterest (0.0.1)
5
+ faraday (>= 1)
6
+ faraday-multipart (>= 1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.5)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
+ ast (2.4.2)
14
+ base64 (0.2.0)
15
+ byebug (11.1.3)
16
+ crack (0.4.5)
17
+ rexml
18
+ diff-lcs (1.5.0)
19
+ dotenv (2.8.1)
20
+ faraday (2.7.11)
21
+ base64
22
+ faraday-net_http (>= 2.0, < 3.1)
23
+ ruby2_keywords (>= 0.0.4)
24
+ faraday-multipart (1.0.4)
25
+ multipart-post (~> 2)
26
+ faraday-net_http (3.0.2)
27
+ hashdiff (1.0.1)
28
+ json (2.6.3)
29
+ multipart-post (2.3.0)
30
+ parallel (1.23.0)
31
+ parser (3.2.2.4)
32
+ ast (~> 2.4.1)
33
+ racc
34
+ public_suffix (5.0.3)
35
+ racc (1.7.3)
36
+ rainbow (3.1.1)
37
+ rake (13.1.0)
38
+ regexp_parser (2.8.2)
39
+ rexml (3.2.6)
40
+ rspec (3.12.0)
41
+ rspec-core (~> 3.12.0)
42
+ rspec-expectations (~> 3.12.0)
43
+ rspec-mocks (~> 3.12.0)
44
+ rspec-core (3.12.2)
45
+ rspec-support (~> 3.12.0)
46
+ rspec-expectations (3.12.3)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.12.0)
49
+ rspec-mocks (3.12.6)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.12.0)
52
+ rspec-support (3.12.1)
53
+ rubocop (1.50.2)
54
+ json (~> 2.3)
55
+ parallel (~> 1.10)
56
+ parser (>= 3.2.0.0)
57
+ rainbow (>= 2.2.2, < 4.0)
58
+ regexp_parser (>= 1.8, < 3.0)
59
+ rexml (>= 3.2.5, < 4.0)
60
+ rubocop-ast (>= 1.28.0, < 2.0)
61
+ ruby-progressbar (~> 1.7)
62
+ unicode-display_width (>= 2.4.0, < 3.0)
63
+ rubocop-ast (1.29.0)
64
+ parser (>= 3.2.1.0)
65
+ ruby-progressbar (1.13.0)
66
+ ruby2_keywords (0.0.5)
67
+ unicode-display_width (2.5.0)
68
+ vcr (6.1.0)
69
+ webmock (3.18.1)
70
+ addressable (>= 2.8.0)
71
+ crack (>= 0.3.2)
72
+ hashdiff (>= 0.4.0, < 2.0.0)
73
+
74
+ PLATFORMS
75
+ x86_64-darwin-19
76
+
77
+ DEPENDENCIES
78
+ byebug (~> 11.1.3)
79
+ dotenv (~> 2.8.1)
80
+ rails-pinterest!
81
+ rake (~> 13.0)
82
+ rspec (~> 3.12)
83
+ rubocop (~> 1.50.2)
84
+ vcr (~> 6.1.0)
85
+ webmock (~> 3.18.1)
86
+
87
+ BUNDLED WITH
88
+ 2.4.20
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Donald Lee
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,200 @@
1
+ # Ruby Pinterest
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/ruby-openai.svg)](https://badge.fury.io/rb/rails-pinterest)
4
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/royalgiant/rails-pinterest/blob/main/LICENSE.txt)
5
+
6
+ Use the [Pinterest API](https://developers.pinterest.com/docs/api/v5/) with Rails!
7
+
8
+ List, Get, Create, Update and Delete Pins, Boards, and Board Sections with Rails Pinterest API
9
+
10
+ 🚢 Based in the US and want to hire me? Now you can! [Email Me](mailto:donaldlee50@gmail.com)
11
+
12
+ [🐦 Twitter](https://twitter.com/donaldlee50) | [▶️ Youtube](https://youtube.com/c/donaldklee)
13
+
14
+ ### Bundler
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem "rails-pinterest"
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```bash
25
+ $ bundle install
26
+ ```
27
+
28
+ ### Gem install
29
+
30
+ Or install with:
31
+
32
+ ```bash
33
+ $ gem install rails-pinterest
34
+ ```
35
+
36
+ and require with:
37
+
38
+ ```ruby
39
+ require "pinterest"
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ - Get your API access from [https://developers.pinterest.com/apps/](https://developers.pinterest.com/apps/)
45
+ - After creating an app, click into the app to generate an access token
46
+ - Or for automated refreshing of tokens check out this [guide](https://developers.pinterest.com/docs/getting-started/authentication/) (this is done in your own app and is unavailable on the API)
47
+
48
+ ### Quickstart
49
+
50
+ For a quick test you can pass your token directly to a new client:
51
+
52
+ ```ruby
53
+ client = Pinterest::Client.new(access_token: "pina_access_token_goes_here")
54
+ ```
55
+
56
+ ### With Config
57
+
58
+ For a more robust setup, you can configure the gem with your API keys, for example in an `pinterest.rb` initializer file. Never hardcode secrets into your codebase - instead use something like [dotenv](https://github.com/motdotla/dotenv) to pass the keys safely into your environments.
59
+
60
+ ```ruby
61
+ Pinterest.configure do |config|
62
+ config.access_token = ENV.fetch("PINTEREST_ACCESS_TOKEN")
63
+ end
64
+ ```
65
+ If you use Rails 7, you would probably store your key in credentials.yml, then you can do something like this:
66
+ ```ruby
67
+ Pinterest.configure do |config|
68
+ config.access_token = Rails.application.credentials[Rails.env.to_sym].dig(:pinterest, :api_key)
69
+ end
70
+ ```
71
+
72
+ Then you can create a client like this:
73
+
74
+ ```ruby
75
+ client = Pinterest::Client.new
76
+ ```
77
+
78
+ You can still override the config defaults when making new clients; any options not included will fall back to any global config set with Pinterest.configure. e.g. in this example the uri_base, request_timeout, etc. will fallback to any set globally using Pinterest.configure, with only the access_token overridden:
79
+
80
+ ```ruby
81
+ client = Pinterest::Client.new(access_token: "access_token_goes_here")
82
+ ```
83
+
84
+ #### Custom timeout or base URI
85
+
86
+ The default timeout for any request using this library is 120 seconds. You can change that by passing a number of seconds to the `request_timeout` when initializing the client. You can also change the base URI used for all requests.
87
+
88
+ ```ruby
89
+ client = Pinterest::Client.new(
90
+ access_token: "access_token_goes_here",
91
+ uri_base: "https://api.pinterest.com/",
92
+ request_timeout: 240,
93
+ extra_headers: {
94
+ "accept" => "application/json",
95
+ "content-type": "application/json",
96
+ }
97
+ )
98
+ ```
99
+
100
+ or when configuring the gem:
101
+
102
+ ```ruby
103
+ Pinterest.configure do |config|
104
+ config.access_token = ENV.fetch("PINTEREST_ACCESS_TOKEN") # Or Rails.application.credentials[Rails.env.to_sym].dig(:pinterest, :api_key) for Rails 7
105
+ config.uri_base = "https://api.pinterest.com/",
106
+ config.request_timeout = 240 # Optional
107
+ config.extra_headers = {
108
+ "accept" => "application/json",
109
+ "content-type": "application/json",
110
+ } # Optional
111
+ end
112
+ ```
113
+ ### Running in Console
114
+ Easily run tests in console with ```bin/console```
115
+
116
+ ```ruby
117
+ # Examples
118
+
119
+ # Getting a board
120
+ client = Pinterest::Client.new(access_token: "your-access-token-here")
121
+ response = client.boards.get_boards
122
+
123
+ puts response
124
+ # => {"items"=>[{"description"=>"", "owner"=>{"username"=>"otakuweebcloset"}, "pin_count"=>18, "created_at"=>"2023-04-29T02:51:52", "name"=>"Studio Ghibli", "follower_count"=>38, "id"=>"996421554995231927", "privacy"=>"PUBLIC", "collaborator_count"=>1, "media"=>{"pin_thumbnail_urls"=>["https://i.pinimg.com/150x150/d2/62/89/d26289f4b7a6e416fad950d2852c4efd.jpg", "https://i.pinimg.com/150x150/d3/e5/56/d3e556ee6420375d1569b8bf4ed601d3.jpg", "https://i.pinimg.com/150x150/fc/76/6c/fc766c458b76bc4086c2f0a1516d8a72.jpg", "https://i.pinimg.com/150x150/83/8f/0b/838f0b7c5ede1b463c5308c82d36670f.jpg", "https://i.pinimg.com/150x150/b9/31/e9/b931e904ca48b2efcfc2b80fe8b3667e.jpg"], "image_cover_url"=>"https://i.pinimg.com/400x300/8b/32/30/8b3230e318f9ed950b6da24a727d4895.jpg"}, "board_pins_modified_at"=>"2023-06-20T16:00:18.116000"}], "bookmark"=>nil}
125
+
126
+ # Getting a pin
127
+ client.pins.get_pin(id: 996421486285872538)
128
+ # => {"board_owner"=>{"username"=>"otakuweebcloset"}, "created_at"=>"2023-05-03T04:45:05", "creative_type"=>"REGULAR",....
129
+
130
+ # Getting a list of board pins
131
+ client.boards.get_board_pins(id: 996421554995231927)
132
+ # => {"items"=>[{"description"=>"The full mystery is revealed in our....
133
+ ```
134
+
135
+ ### Boards
136
+
137
+ How to do simple get and post with boards
138
+
139
+ ```ruby
140
+ # https://developers.pinterest.com/docs/api/v5/
141
+
142
+ # GET list of boards
143
+
144
+ response = client.boards.get_boards
145
+
146
+ # POST to create a board
147
+ parameters = {
148
+ :name=>"give it some name",
149
+ :description=>"and a description"
150
+ }
151
+ response = client.pins.create_board(parameters: parameters)
152
+ ```
153
+
154
+ ### Pins
155
+
156
+ How to do simple get and post with pins
157
+
158
+ ```ruby
159
+ # https://developers.pinterest.com/docs/api/v5/
160
+
161
+ # GET list of pins
162
+
163
+ response = client.pins.get_pin(id: 996421486285872538)
164
+
165
+ # POST to create a pin
166
+ parameters = {
167
+ :board_id=>some_id,
168
+ :media_source=>{
169
+ source_type: "image_url",
170
+ url: "https://imagifyr.com/assets/home_logo-a52a3541ab2751e842ac524a7e20e85218d26732face6731494b87c32712eace.png",
171
+ }
172
+ }
173
+ response = client.pins.create_pin(parameters: parameters)
174
+
175
+ ```
176
+
177
+ ## Development
178
+
179
+ After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
180
+
181
+ To install this gem onto your local machine, run `bundle exec rake install`.
182
+
183
+ ## Release
184
+
185
+ Update the version number in `version.rb`, update `CHANGELOG.md`, run `bundle install` to update Gemfile.lock, 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).
186
+
187
+ ## Contributing
188
+
189
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/royalgiant/rails-pinterest>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/royalgiant/rails-pinterest/blob/main/CODE_OF_CONDUCT.md).
190
+
191
+ ## License
192
+
193
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
194
+
195
+ ## Code of Conduct
196
+
197
+ Everyone interacting in the Ruby Pinterest project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/royalgiant/rails-pinterest/blob/main/CODE_OF_CONDUCT.md).
198
+
199
+ ## Influences
200
+ Project heavily influenced by [https://github.com/alexrudall/ruby-openai](https://github.com/alexrudall/ruby-openai). Great project, go give them a star!
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
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 "ruby/pinterest"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,51 @@
1
+ module Pinterest
2
+ class Boards
3
+ def initialize(client: nil)
4
+ @client = client
5
+ end
6
+
7
+ def get_boards(parameters: {})
8
+ @client.get(path: "/boards", parameters: parameters)
9
+ end
10
+
11
+ def create_board(parameters: {})
12
+ @client.json_post(path: "/boards", parameters: parameters)
13
+ end
14
+
15
+ def get_board(id:, parameters: {})
16
+ @client.get(path: "/boards/#{id}", parameters: parameters)
17
+ end
18
+
19
+ def update_board(id:, parameters: {})
20
+ @client.patch(path: "/boards/#{id}", parameters: parameters)
21
+ end
22
+
23
+ def delete_board(id:)
24
+ @client.delete(path: "/boards/#{id}")
25
+ end
26
+
27
+ def get_board_pins(id:, parameters: {})
28
+ @client.get(path: "/boards/#{id}/pins", parameters: parameters)
29
+ end
30
+
31
+ def get_board_sections(id:, parameters: {})
32
+ @client.get(path: "/boards/#{id}/sections", parameters: parameters)
33
+ end
34
+
35
+ def create_board_sections(id:, parameters: {})
36
+ @client.json_post(path: "/boards/#{}/sections", parameters: parameters)
37
+ end
38
+
39
+ def update_board_section(id:, section_id:, parameters: {})
40
+ @client.patch(path: "/boards/#{id}/sections/#{section_id}", parameters: parameters)
41
+ end
42
+
43
+ def delete_board_section(id:, section_id:)
44
+ @client.patch(path: "/boards/#{id}/sections/#{section_id}")
45
+ end
46
+
47
+ def get_board_section_pins(id:, section_id:, parameters: {})
48
+ @client.get(path: "/boards/#{id}/sections/#{section_id}/pins", parameters: parameters)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,31 @@
1
+ module Pinterest
2
+ class Client
3
+ include Pinterest::HTTP
4
+
5
+ CONFIG_KEYS = %i[
6
+ api_type
7
+ api_version
8
+ access_token
9
+ uri_base
10
+ request_timeout
11
+ extra_headers
12
+ ].freeze
13
+ attr_reader *CONFIG_KEYS
14
+
15
+ def initialize(config = {})
16
+ CONFIG_KEYS.each do |key|
17
+ # Set instance variables like api_type & access_token. Fall back to global config
18
+ # if not present.
19
+ instance_variable_set("@#{key}", config[key] || Pinterest.configuration.send(key))
20
+ end
21
+ end
22
+
23
+ def boards
24
+ @boards ||= Pinterest::Boards.new(client: self)
25
+ end
26
+
27
+ def pins
28
+ @pins ||= Pinterest::Pins.new(client: self)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ module Ruby
2
+ module Pinterest
3
+ VERSION = ::Pinterest::VERSION
4
+
5
+ Error = ::Pinterest::Error
6
+ ConfigurationError = ::Pinterest::ConfigurationError
7
+ Configuration = ::Pinterest::Configuration
8
+ end
9
+ end
@@ -0,0 +1,81 @@
1
+ module Pinterest
2
+ module HTTP
3
+ def get(path:, parameters:)
4
+ to_json(conn.get(uri(path: path)) do |req|
5
+ req.headers = headers
6
+ req.body = parameters.to_json
7
+ end&.body)
8
+ end
9
+
10
+ def json_post(path:, parameters:)
11
+ to_json(conn.post(uri(path: path)) do |req|
12
+ req.headers = headers
13
+ req.body = parameters.to_json
14
+ end&.body)
15
+ end
16
+
17
+ def patch(path:, parameters:)
18
+ to_json(conn.patch(uri(path: path)) do |req|
19
+ req.headers = headers
20
+ req.body = parameters.to_json
21
+ end&.body)
22
+ end
23
+
24
+ def multipart_post(path:, parameters: nil)
25
+ to_json(conn(multipart: true).post(uri(path: path)) do |req|
26
+ req.headers = headers.merge({ "Content-Type" => "multipart/form-data" })
27
+ req.body = multipart_parameters(parameters)
28
+ end&.body)
29
+ end
30
+
31
+ def delete(path:)
32
+ to_json(conn.delete(uri(path: path)) do |req|
33
+ req.headers = headers
34
+ end&.body)
35
+ end
36
+
37
+ private
38
+
39
+ def to_json(string)
40
+ return unless string
41
+
42
+ JSON.parse(string)
43
+ rescue JSON::ParserError
44
+ # Convert a multiline string of JSON objects to a JSON array.
45
+ JSON.parse(string.gsub("}\n{", "},{").prepend("[").concat("]"))
46
+ end
47
+
48
+ def conn(multipart: false)
49
+ Faraday.new do |f|
50
+ f.options[:timeout] = @request_timeout
51
+ f.request(:multipart) if multipart
52
+ end
53
+ end
54
+
55
+ def uri(path:)
56
+ File.join(@uri_base, @api_version, path)
57
+ end
58
+
59
+ def headers
60
+ pinterest_headers.merge(@extra_headers || {})
61
+ end
62
+
63
+ def pinterest_headers
64
+ {
65
+ "Content-Type" => "application/json",
66
+ "Authorization" => "Bearer #{@access_token}",
67
+ }
68
+ end
69
+
70
+ def multipart_parameters(parameters)
71
+ parameters&.transform_values do |value|
72
+ next value unless value.respond_to?(:close) # File or IO object.
73
+
74
+ # Doesn't seem like OpenAI needs mime_type yet, so not worth
75
+ # the library to figure this out. Hence the empty string
76
+ # as the second argument.
77
+ Faraday::UploadIO.new(value, "", value.path)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,36 @@
1
+ module Pinterest
2
+ class Pins
3
+ def initialize(client: nil)
4
+ @client = client
5
+ end
6
+
7
+ def list_pins(parameters: {})
8
+ @client.get(path: "/pins", parameters: parameters)
9
+ end
10
+
11
+ def create_pin(parameters: {})
12
+ @client.json_post(path: "/pins", parameters: parameters)
13
+ end
14
+
15
+ def get_pin(id:, parameters: {})
16
+ @client.get(path: "/pins/#{id}", parameters: parameters)
17
+ end
18
+
19
+ def delete_pin(id:)
20
+ @client.delete(path: "/pins/#{id}")
21
+ end
22
+
23
+ def update_pin(id: , parameters: {})
24
+ @client.patch(path: "/pins/#{id}", parameters: parameters)
25
+ end
26
+
27
+ def get_pin_analytics(id:, parameters: {})
28
+ @client.get(path: "/pins/#{id}/analytics", parameters: parameters)
29
+ end
30
+
31
+ def save_pin(id: , parameters: {})
32
+ @client.json_post(path: "/pins/#{id}/save", parameters: parameters)
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Pinterest
2
+ VERSION = "0.1.0"
3
+ end
data/lib/pinterest.rb ADDED
@@ -0,0 +1,54 @@
1
+ require "faraday"
2
+ require "faraday/multipart"
3
+ require_relative "pinterest/http"
4
+ require_relative "pinterest/client"
5
+ require_relative "pinterest/boards"
6
+ require_relative "pinterest/pins"
7
+ require_relative "pinterest/version"
8
+
9
+ module Pinterest
10
+ class Error < StandardError; end
11
+ class ConfigurationError < Error; end
12
+
13
+ class Configuration
14
+ attr_writer :access_token
15
+ attr_accessor :api_type, :api_version, :uri_base, :request_timeout,
16
+ :extra_headers
17
+
18
+ DEFAULT_API_VERSION = "v5".freeze
19
+ DEFAULT_URI_BASE = "https://api.pinterest.com/".freeze
20
+ DEFAULT_REQUEST_TIMEOUT = 120
21
+
22
+ def initialize
23
+ @access_token = nil
24
+ @api_type = nil
25
+ @api_version = DEFAULT_API_VERSION
26
+ @uri_base = DEFAULT_URI_BASE
27
+ @request_timeout = DEFAULT_REQUEST_TIMEOUT
28
+ @extra_headers = {
29
+ "accept" => "application/json",
30
+ "content-type" => "application/json"
31
+ }
32
+ end
33
+
34
+ def access_token
35
+ return @access_token if @access_token
36
+
37
+ error_text = "Pinterest access token missing! See https://github.com/alexrudall/ruby-openai#usage"
38
+ raise ConfigurationError, error_text
39
+ end
40
+ end
41
+
42
+ class << self
43
+ attr_writer :configuration
44
+ end
45
+
46
+ def self.configuration
47
+ @configuration ||= Pinterest::Configuration.new
48
+ end
49
+
50
+ def self.configure
51
+ yield(configuration)
52
+ end
53
+ end
54
+
@@ -0,0 +1,2 @@
1
+ require_relative "../pinterest"
2
+ require_relative "../pinterest/compatibility"
@@ -0,0 +1,35 @@
1
+ require_relative "lib/pinterest/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "rails-pinterest"
5
+ spec.version = Pinterest::VERSION
6
+ spec.authors = ["Donald Lee"]
7
+ spec.email = ["donaldlee50@gmail.com"]
8
+
9
+ spec.summary = "Pinterest API + Ruby!"
10
+ spec.homepage = "https://github.com/royalgiant/rails-pinterest"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
13
+ spec.metadata["rubygems_mfa_required"] = "true"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/royalgiant/rails-pinterest"
17
+ spec.metadata["changelog_uri"] = "https://github.com/royalgiant/rails-pinterest/blob/main/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ # Uncomment to register a new dependency of your gem
29
+ # spec.add_dependency "example-gem", "~> 1.0"
30
+
31
+ # For more information and examples about making a new gem, check out our
32
+ # guide at: https://bundler.io/guides/creating_gem.html
33
+ spec.add_dependency "faraday", ">= 1"
34
+ spec.add_dependency "faraday-multipart", ">= 1"
35
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-pinterest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Donald Lee
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-multipart
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ description:
42
+ email:
43
+ - donaldlee50@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CHANGELOG.md
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - lib/pinterest.rb
59
+ - lib/pinterest/boards.rb
60
+ - lib/pinterest/client.rb
61
+ - lib/pinterest/compatibility.rb
62
+ - lib/pinterest/http.rb
63
+ - lib/pinterest/pins.rb
64
+ - lib/pinterest/version.rb
65
+ - lib/ruby/pinterest.rb
66
+ - rails-pinterest.gemspec
67
+ homepage: https://github.com/royalgiant/rails-pinterest
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ rubygems_mfa_required: 'true'
72
+ homepage_uri: https://github.com/royalgiant/rails-pinterest
73
+ source_code_uri: https://github.com/royalgiant/rails-pinterest
74
+ changelog_uri: https://github.com/royalgiant/rails-pinterest/blob/main/CHANGELOG.md
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 2.6.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.2.3
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Pinterest API + Ruby!
94
+ test_files: []