pingboard 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +80 -0
- data/lib/pingboard.rb +3 -0
- data/lib/pingboard/client.rb +90 -0
- data/pingboard.gemspec +16 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2dddbd8a55fc10971311e036642adfd6d09575dd
|
4
|
+
data.tar.gz: 9ad143a7c4e3d0b6fc50ce65fb00cdc3ccfb11f7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6aa39f72878ca072f33cedd4c168968e2de8b29f883f001d413d77a826d4c7bea2a3a2dea042f6dcd3f229fd9d15013b21ed49e7c08d1bf5cd08a4353ca993b4
|
7
|
+
data.tar.gz: a4fbcffccb1526273bc449c1f0f8095b0b34a1d1a876d6e218ec8642fcc4b4a47d784624bafc5fc8b0308bb35076df610f30cfe62dd08c4476ea45fc8c4e163c
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Pingboard API Ruby Client
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/pingboard.svg)](https://rubygems.org/gems/pingboard)
|
4
|
+
[![Build Status](https://travis-ci.org/bry/pingboard.svg)](https://travis-ci.org/bry/pingboard)
|
5
|
+
|
6
|
+
The Ruby interface to the Pingboard API
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install pingboard
|
12
|
+
```
|
13
|
+
|
14
|
+
## Configuration
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
client = Pingboard::Client.new do |config|
|
18
|
+
config.service_app_id = 'service app id'
|
19
|
+
config.service_app_secret = 'service app secret'
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage Examples
|
24
|
+
After configuring a `client`, you can do the following:
|
25
|
+
|
26
|
+
### Search
|
27
|
+
Search for a Pingboard user
|
28
|
+
```ruby
|
29
|
+
client.search("Pingboard text query")
|
30
|
+
```
|
31
|
+
|
32
|
+
### Users
|
33
|
+
Get all Pingboard users
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
client.users
|
37
|
+
```
|
38
|
+
|
39
|
+
Get a Pingboard user by user ID
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
client.user("12345")
|
43
|
+
```
|
44
|
+
|
45
|
+
### Status
|
46
|
+
|
47
|
+
Get a Pingboard status by status ID
|
48
|
+
```ruby
|
49
|
+
client.status("12345")
|
50
|
+
```
|
51
|
+
|
52
|
+
### Status Types
|
53
|
+
|
54
|
+
Get Pingboard's status types
|
55
|
+
```ruby
|
56
|
+
client.status_types
|
57
|
+
```
|
58
|
+
|
59
|
+
## License
|
60
|
+
MIT License
|
61
|
+
|
62
|
+
Copyright (c) 2017 Bryan B. Cabalo
|
63
|
+
|
64
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
65
|
+
of this software and associated documentation files (the "Software"), to deal
|
66
|
+
in the Software without restriction, including without limitation the rights
|
67
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
68
|
+
copies of the Software, and to permit persons to whom the Software is
|
69
|
+
furnished to do so, subject to the following conditions:
|
70
|
+
|
71
|
+
The above copyright notice and this permission notice shall be included in all
|
72
|
+
copies or substantial portions of the Software.
|
73
|
+
|
74
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
75
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
76
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
77
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
78
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
79
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
80
|
+
SOFTWARE.
|
data/lib/pingboard.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
module Pingboard
|
2
|
+
class Client
|
3
|
+
|
4
|
+
URL_HOSTNAME = 'https://app.pingboard.com'.freeze
|
5
|
+
URL_API_VERSION_PATH = '/api/v2'.freeze
|
6
|
+
URL_SEARCH_USERS_PATH = '/search/users'.freeze
|
7
|
+
URL_USERS_PATH = '/users'.freeze
|
8
|
+
URL_STATUSES_PATH = '/statuses'.freeze
|
9
|
+
URL_STATUS_TYPES_PATH = '/status_types'.freeze
|
10
|
+
URL_OAUTH_TOKEN_PATH = '/oauth/token'.freeze
|
11
|
+
|
12
|
+
attr_accessor :connection, :service_app_id, :service_app_secret,
|
13
|
+
:access_token, :token_expires_in, :token_expiration_time
|
14
|
+
|
15
|
+
def initialize(options={})
|
16
|
+
options.each do |key, value|
|
17
|
+
instance_variable_set("@#{key}", value)
|
18
|
+
end
|
19
|
+
yield(self) if block_given?
|
20
|
+
@token_expiration_time = Time.now
|
21
|
+
end
|
22
|
+
|
23
|
+
def search(query, options={})
|
24
|
+
options.merge(q: query)
|
25
|
+
perform_get_request(URL_API_VERSION_PATH + URL_SEARCH_USERS_PATH, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def users(options={})
|
29
|
+
perform_get_request(URL_API_VERSION_PATH + URL_USERS_PATH, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def user(user_id, options={})
|
33
|
+
perform_get_request(URL_API_VERSION_PATH + URL_USERS_PATH + "/#{user_id}", options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def status(status_id, options={})
|
37
|
+
perform_get_request(URL_API_VERSION_PATH + URL_STATUSES_PATH + "/#{status_id}", options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def status_types
|
41
|
+
perform_get_request(URL_API_VERSION_PATH + URL_STATUS_TYPES_PATH)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def connection
|
48
|
+
@connection = Faraday.new(url: URL_HOSTNAME)
|
49
|
+
end
|
50
|
+
|
51
|
+
def access_token_expired?
|
52
|
+
Time.now > token_expiration_time
|
53
|
+
end
|
54
|
+
|
55
|
+
def new_access_token
|
56
|
+
response_body = JSON.parse(access_token_request.body)
|
57
|
+
@token_expires_in = response_body['expires_in']
|
58
|
+
@token_expiration_time = Time.now + @token_expires_in.to_i
|
59
|
+
response_body['access_token']
|
60
|
+
end
|
61
|
+
|
62
|
+
def access_token
|
63
|
+
@access_token = new_access_token if access_token_expired?
|
64
|
+
@access_token
|
65
|
+
end
|
66
|
+
|
67
|
+
def access_token_request
|
68
|
+
@access_token_request = connection.post do |req|
|
69
|
+
req.url URL_OAUTH_TOKEN_PATH
|
70
|
+
req.params['grant_type'] = 'client_credentials'
|
71
|
+
req.body = {
|
72
|
+
client_id: service_app_id,
|
73
|
+
client_secret: service_app_secret
|
74
|
+
}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def perform_get_request(url_path, options={})
|
79
|
+
pingboard_response = connection.get do |req|
|
80
|
+
req.url "#{url_path}"
|
81
|
+
req.headers['Authorization'] = "Bearer #{access_token}"
|
82
|
+
options.each do |key, value|
|
83
|
+
req.params["#{key}"] = value
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
JSON.parse(pingboard_response.body)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/pingboard.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'pingboard'
|
6
|
+
s.version = '0.0.1'
|
7
|
+
s.date = '2017-07-16'
|
8
|
+
s.summary = "The Pingboard API Ruby Client"
|
9
|
+
s.description = "A Ruby client interface for the Pingboard API"
|
10
|
+
s.authors = ["Bryan B. Cabalo"]
|
11
|
+
s.email = 'bcabalo@gmail.com'
|
12
|
+
s.require_paths = %w(lib)
|
13
|
+
s.files = %w(lib/pingboard.rb README.md pingboard.gemspec) + Dir['lib/**/*.rb']
|
14
|
+
s.homepage = 'http://rubygems.org/gems/pingboard'
|
15
|
+
s.license = 'MIT'
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pingboard
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bryan B. Cabalo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Ruby client interface for the Pingboard API
|
14
|
+
email: bcabalo@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- lib/pingboard.rb
|
21
|
+
- lib/pingboard/client.rb
|
22
|
+
- pingboard.gemspec
|
23
|
+
homepage: http://rubygems.org/gems/pingboard
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.5.1
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: The Pingboard API Ruby Client
|
47
|
+
test_files: []
|