pinterest-api 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 62f3ada09f30718758f52b7d1d117b3fff499df7
4
+ data.tar.gz: 2e8a9a59ac855f76a9ecb7477cb7aecd8582a4fd
5
+ SHA512:
6
+ metadata.gz: c39ecfaf4a9a4e59af34b0a2025721e4ece28cc180a14c1153b414d30639a89f7c29998ee524edf903c82b5d6f09e296d22b3a4e6273990c3935e413e5e10e03
7
+ data.tar.gz: 2e5247eb424861dc70229bbfaf55d9d9f4f22f4ac431db9fdcee9cd7cf9379dd3a2356a046db850eb5814ed03695ae9899fb8b8b8cf5fbd9bd92e5abd9049ccf
@@ -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
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pinterest.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Adeel Ahmad
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,83 @@
1
+ # Pinterest
2
+
3
+ [![Code Climate](https://codeclimate.com/github/realadeel/pinterest-api/badges/gpa.svg)](https://codeclimate.com/github/realadeel/pinterest-api)
4
+
5
+ This is the Ruby gem for interacting with the official [Pinterest REST API](https://developers.pinterest.com/docs/getting-started/introduction/).
6
+
7
+ This gem uses Faraday and Hashie to make requests and parse the responses.
8
+
9
+ ## Usage
10
+
11
+ Obtain an access token from Pinterest. You can generate one [here](https://developers.pinterest.com/docs/api/access_token/).
12
+
13
+ $ gem install pinterest
14
+
15
+ ```ruby
16
+ require 'pinterest-api'
17
+
18
+ client = Pinterest::Client.new(ACCESS_TOKEN)
19
+
20
+ # Get the authenticated user's Pinterest account info
21
+ client.me
22
+
23
+ # Get the pins that the authenticated user likes
24
+ client.get_likes
25
+
26
+ # Get the authenticated user's followers
27
+ client.get_followers
28
+
29
+ # Get the boards that the authenticated user follows
30
+ client.get_followed_boards
31
+
32
+ # Get the Pinterest users that the authenticated user follows
33
+ client.get_followed_users
34
+
35
+ # Get the interests that the authenticated user follows
36
+ client.get_followed_interests
37
+
38
+ # Follow a user
39
+ client.follow_user('shopseen')
40
+
41
+ # Unfollow a user
42
+ client.unfollow_user('shopseen')
43
+
44
+ # Follow a board
45
+ client.follow_board(<board_id>)
46
+
47
+ # Unfollow a board
48
+ client.unfollow_board(<board_id>)
49
+
50
+ # Follow an interest
51
+ client.follow_interest(<interest_id>)
52
+
53
+ # Unfollow an interest
54
+ client.unfollow_interest(<interest_id>)
55
+
56
+ # Search for authenticated users's pins related to shoes
57
+ client.get_pins(query: 'shoes')
58
+
59
+ # Search for authenticated users's boards related to shoes
60
+ client.get_boards(query: 'shoes')
61
+
62
+ # Get the account info for a Pinterest user
63
+ client.get_user('<username>')
64
+
65
+ ```
66
+
67
+ The gem is currently under active development. Use at your own risk. See Known Issues below.
68
+ I hope to have the gem ready for production shortly. See Contributing section below to help.
69
+
70
+ ## Known Issues
71
+
72
+ * PATCH requests not working, endpoint path is not being appended to base
73
+
74
+ ## TODO
75
+
76
+ * Pagination
77
+ * OAuth
78
+ * document Mash response methods
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/realadeel/pinterest-api.
83
+ Please provide a failing test for bug reports, and a passing test for pull requests.
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pinterest"
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
@@ -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,6 @@
1
+ require "pinterest/version"
2
+ require "pinterest/client"
3
+
4
+ module Pinterest
5
+
6
+ end
@@ -0,0 +1,93 @@
1
+ require 'faraday_middleware'
2
+ require 'pinterest/client/user'
3
+ require 'pinterest/client/pin'
4
+ require 'pinterest/client/board'
5
+
6
+ module Pinterest
7
+ class Client
8
+
9
+ include Pinterest::Client::User
10
+ include Pinterest::Client::Pin
11
+ include Pinterest::Client::Board
12
+
13
+ BASE_ENDPOINT = 'https://api.pinterest.com/v1/'.freeze
14
+ DEFAULT_USER_AGENT = "Pinterest Ruby Gem #{Pinterest::VERSION}".freeze
15
+ DEFAULT_ADAPTER = Faraday.default_adapter
16
+
17
+ def initialize(access_token = nil)
18
+ @access_token = access_token
19
+ end
20
+
21
+ attr_reader :access_token
22
+
23
+ def get(path, options={})
24
+ request(:get, path, options)
25
+ end
26
+
27
+ def post(path, options={})
28
+ request(:post, path, options)
29
+ end
30
+
31
+ def patch(path, options={})
32
+ request(:patch, path, options)
33
+ end
34
+
35
+ def put(path, options={})
36
+ request(:put, path, options)
37
+ end
38
+
39
+ def delete(path, options={})
40
+ request(:delete, path, options)
41
+ end
42
+
43
+ private
44
+
45
+ def request(method, path, options)
46
+ raw = options.delete(:raw)
47
+ log = options.delete(:log)
48
+ path = File.join(path, '')
49
+ response = connection(raw, log).send(method) do |request|
50
+ case method
51
+ when :get
52
+ path = path + "?access_token=" + @access_token
53
+ request.url(URI.encode(path), options)
54
+ when :post, :put, :delete
55
+ request.path = URI.encode(path)
56
+ request.body = options unless options.empty?
57
+ request.headers['Authorization'] = "BEARER #{@access_token}"
58
+ end
59
+ end
60
+ return response.body
61
+ end
62
+
63
+ def connection(raw = false, log = false)
64
+ options = {
65
+ :headers => {'Accept' => "application/json; charset=utf-8", 'User-Agent' => user_agent},
66
+ :url => endpoint,
67
+ }
68
+
69
+ Faraday::Connection.new(options) do |connection|
70
+ unless raw
71
+ connection.use FaradayMiddleware::Mashify
72
+ end
73
+ connection.use Faraday::Response::ParseJson
74
+ connection.use Faraday::Request::UrlEncoded
75
+ connection.response :logger if log
76
+ connection.adapter(adapter)
77
+ end
78
+ end
79
+
80
+ def endpoint
81
+ BASE_ENDPOINT
82
+ end
83
+
84
+ def user_agent
85
+ DEFAULT_USER_AGENT
86
+ end
87
+
88
+ def adapter
89
+ DEFAULT_ADAPTER
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,23 @@
1
+ module Pinterest
2
+ class Client
3
+ module Board
4
+
5
+ def get_board(id)
6
+ get("boards/#{id}")
7
+ end
8
+
9
+ def create_board(params={})
10
+ post('boards', params)
11
+ end
12
+
13
+ def update_board(params={})
14
+ patch('boards', params)
15
+ end
16
+
17
+ def delete_board(id)
18
+ delete("boards/#{id}")
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Pinterest
2
+ class Client
3
+ module Pin
4
+
5
+ def get_pin(id)
6
+ get("pins/#{id}")
7
+ end
8
+
9
+ def get_board_pins(board_id)
10
+ get("boards/#{board_id}/pins")
11
+ end
12
+
13
+ def create_pin(params={})
14
+ post('pins', params)
15
+ end
16
+
17
+ def update_pin(params={})
18
+ patch('pins', params)
19
+ end
20
+
21
+ def delete_pin(id)
22
+ delete("pins/#{id}")
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,67 @@
1
+ module Pinterest
2
+ class Client
3
+ module User
4
+
5
+ def me
6
+ get('me')
7
+ end
8
+
9
+ def get_followers
10
+ get("me/followers")
11
+ end
12
+
13
+ def get_likes
14
+ get("me/likes")
15
+ end
16
+
17
+ def get_followed_boards
18
+ get("me/following/boards")
19
+ end
20
+
21
+ def get_followed_users
22
+ get("me/following/users")
23
+ end
24
+
25
+ def get_followed_interests
26
+ get("me/following/interests")
27
+ end
28
+
29
+ def follow_user(user)
30
+ post('me/following/users', user: user)
31
+ end
32
+
33
+ def unfollow_user(user)
34
+ delete("me/following/users/#{user}")
35
+ end
36
+
37
+ def follow_board(board_id)
38
+ post('me/following/boards', board: board_id)
39
+ end
40
+
41
+ def unfollow_board(board_id)
42
+ delete("me/following/boards/#{board_id}")
43
+ end
44
+
45
+ def follow_interest(interest_id)
46
+ post('me/following/interests', interest: interest_id)
47
+ end
48
+
49
+ def unfollow_interest(interest_id)
50
+ delete("me/following/interests/#{interest_id}")
51
+ end
52
+
53
+ def search_pins(params={})
54
+ get('me/search/pins', query: params[:query])
55
+ end
56
+
57
+ def search_boards(params={})
58
+ get('me/search/boards', query: params[:query])
59
+ end
60
+
61
+ def get_user(user)
62
+ get("users/#{user}")
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Pinterest
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pinterest/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pinterest-api"
8
+ spec.version = Pinterest::VERSION
9
+ spec.authors = ["Adeel Ahmad"]
10
+ spec.email = ["adeel.rb@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby gem to interact with the Pinterest REST API}
13
+ spec.description = %q{This gem makes it simple to interact with the official Pinterest REST API}
14
+ spec.homepage = "http://github.com/realadeel"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.3"
25
+ spec.add_development_dependency "vcr", "~> 2.9"
26
+ spec.add_development_dependency "dotenv", "~> 2.0"
27
+
28
+ spec.add_dependency 'faraday', "~> 0.9"
29
+ spec.add_dependency 'faraday_middleware', "~> 0.10"
30
+ spec.add_dependency 'hashie', "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pinterest-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adeel Ahmad
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday_middleware
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.10'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.10'
111
+ - !ruby/object:Gem::Dependency
112
+ name: hashie
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ description: This gem makes it simple to interact with the official Pinterest REST
126
+ API
127
+ email:
128
+ - adeel.rb@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - LICENSE
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - lib/pinterest-api.rb
143
+ - lib/pinterest/client.rb
144
+ - lib/pinterest/client/board.rb
145
+ - lib/pinterest/client/pin.rb
146
+ - lib/pinterest/client/user.rb
147
+ - lib/pinterest/version.rb
148
+ - pinterest.gemspec
149
+ homepage: http://github.com/realadeel
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.5.1
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Ruby gem to interact with the Pinterest REST API
173
+ test_files: []