plangrade-ruby 0.0.2
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 +7 -0
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/certs/public.pem +21 -0
- data/lib/plangrade.rb +31 -0
- data/lib/plangrade/api.rb +3 -0
- data/lib/plangrade/api/company.rb +25 -0
- data/lib/plangrade/api/participant.rb +25 -0
- data/lib/plangrade/api/user.rb +21 -0
- data/lib/plangrade/api_handler.rb +13 -0
- data/lib/plangrade/api_response.rb +43 -0
- data/lib/plangrade/client.rb +74 -0
- data/lib/plangrade/configurable.rb +67 -0
- data/lib/plangrade/error.rb +61 -0
- data/lib/plangrade/http_adapter.rb +86 -0
- data/lib/plangrade/oauth2_client.rb +79 -0
- data/lib/plangrade/resources.rb +5 -0
- data/lib/plangrade/resources/base.rb +196 -0
- data/lib/plangrade/resources/company.rb +19 -0
- data/lib/plangrade/resources/identity_map.rb +44 -0
- data/lib/plangrade/resources/participant.rb +24 -0
- data/lib/plangrade/resources/user.rb +25 -0
- data/lib/plangrade/ruby/version.rb +5 -0
- data/plangrade-ruby.gemspec +39 -0
- data/test/fixtures/one_user.yml +65 -0
- data/test/test_helper.rb +9 -0
- data/test/user/user_test.rb +19 -0
- metadata +267 -0
- metadata.gz.sig +2 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d7c596d5893cea75645c5261e82f5f54c8425090
|
4
|
+
data.tar.gz: 3863c641a23ba4f549a009bd80ea7dca43c390b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aabc8bb6175587689d6ebc088113c7838252623e70c11a58cda8caa35b70d7f692b34b6117652e46bd065bf8323cdcbc7ab1ed863f76d738f86ec23e7a292d5f
|
7
|
+
data.tar.gz: 4503ad38f472ed38f393e0c7c125c4a9a5f42d21362ae0c88bae4bfa085b5a77d1d1b1142926c37d391b9788df14a1a9d59a89dd41c78f5bd7bc79227b2fc7bd
|
checksums.yaml.gz.sig
ADDED
data.tar.gz.sig
ADDED
Binary file
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Christopher Reynoso
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Plangrade::Ruby
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'plangrade-ruby'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install plangrade-ruby
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/plangrade-ruby/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/certs/public.pem
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDhTCCAm2gAwIBAgIBATANBgkqhkiG9w0BAQUFADBEMRYwFAYDVQQDDA10b3Bo
|
3
|
+
ZXJyZXlub3NvMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
|
4
|
+
FgNjb20wHhcNMTQxMTA5MTgxMjE1WhcNMTUxMTA5MTgxMjE1WjBEMRYwFAYDVQQD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Ues6zSSckWtaXKjQRy7OG7yGu
|
20
|
+
2YveeRgxu2nn/J4Q6Obf7PqMvpR0z5T8SUptXcRVhHBZDUzrBpNvtNM=
|
21
|
+
-----END CERTIFICATE-----
|
data/lib/plangrade.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative "plangrade/ruby/version"
|
2
|
+
require_relative "plangrade/error"
|
3
|
+
require_relative "plangrade/configurable"
|
4
|
+
require_relative "plangrade/api"
|
5
|
+
require_relative "plangrade/http_adapter"
|
6
|
+
require_relative "plangrade/oauth2_client"
|
7
|
+
require_relative "plangrade/client"
|
8
|
+
require_relative "plangrade/api_handler"
|
9
|
+
require_relative "plangrade/api_response"
|
10
|
+
require_relative "plangrade/resources"
|
11
|
+
|
12
|
+
module Plangrade
|
13
|
+
class << self
|
14
|
+
include Configurable
|
15
|
+
include ApiHandler
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"<#{self.name}: #{self.options.inspect}>"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def method_missing(method_name, *args, &block)
|
23
|
+
return super unless api_handler.respond_to?(method_name)
|
24
|
+
api_handler.send(method_name, *args, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Plan = Plangrade
|
30
|
+
|
31
|
+
Plangrade.reset!
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Plangrade
|
2
|
+
module Api
|
3
|
+
module Company
|
4
|
+
def create_company(opts = {})
|
5
|
+
post('/api/v1/companies', opts)
|
6
|
+
end
|
7
|
+
|
8
|
+
def update_company(id, opts={})
|
9
|
+
put("/api/v1/companies/#{id}", opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete_company(id)
|
13
|
+
delete("/api/v1/companies/#{id}", opts)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_company(id)
|
17
|
+
get("/api/v1/companies/#{id}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def all_companies(opts={})
|
21
|
+
get("/api/v1/companies", opts)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Plangrade
|
2
|
+
module Api
|
3
|
+
module Participant
|
4
|
+
def create_participant(opts = {})
|
5
|
+
post('/api/v1/participants', opts)
|
6
|
+
end
|
7
|
+
|
8
|
+
def update_participant(id, opts={})
|
9
|
+
put("/api/v1/participants/#{id}", opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete_participant(id)
|
13
|
+
delete("/api/v1/participants/#{id}", opts)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_participant(id)
|
17
|
+
get("/api/v1/participants/#{id}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def all_participants(opts={})
|
21
|
+
get("/api/v1/participants", opts)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Plangrade
|
2
|
+
module Api
|
3
|
+
module User
|
4
|
+
def create_user(opts = {})
|
5
|
+
post('/api/v1/users', opts)
|
6
|
+
end
|
7
|
+
|
8
|
+
def update_user(id, opts={})
|
9
|
+
put("/api/v1/users/#{id}", opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete_user(id)
|
13
|
+
delete("/api/v1/users/#{id}", opts)
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_user
|
17
|
+
get('/api/v1/me')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Plangrade
|
2
|
+
class ApiResponse
|
3
|
+
|
4
|
+
attr_reader :code, :headers
|
5
|
+
|
6
|
+
def initialize(headers, body, code)
|
7
|
+
@headers = headers
|
8
|
+
@body = body
|
9
|
+
@code = code.to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def raw_body
|
13
|
+
@body
|
14
|
+
end
|
15
|
+
|
16
|
+
def body
|
17
|
+
@parsed_body ||= parse(@body)
|
18
|
+
end
|
19
|
+
|
20
|
+
def empty?
|
21
|
+
@body.nil? || @body.strip.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
def success?
|
25
|
+
@code == 200
|
26
|
+
end
|
27
|
+
|
28
|
+
def created?
|
29
|
+
@code == 201
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def parse(body)
|
35
|
+
case body
|
36
|
+
when /\A^\s*$\z/, nil
|
37
|
+
nil
|
38
|
+
else
|
39
|
+
MultiJson.load(body, :symbolize_keys => true)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'plangrade/api'
|
2
|
+
require 'plangrade/configurable'
|
3
|
+
require 'plangrade/http_adapter'
|
4
|
+
|
5
|
+
module Plangrade
|
6
|
+
class Client
|
7
|
+
|
8
|
+
include Plangrade::Configurable
|
9
|
+
include Plangrade::Api::User
|
10
|
+
include Plangrade::Api::Company
|
11
|
+
include Plangrade::Api::Participant
|
12
|
+
|
13
|
+
attr_reader :site_url, :default_headers, :connection_options
|
14
|
+
|
15
|
+
attr_accessor :client_id, :client_secret, :access_token
|
16
|
+
|
17
|
+
def initialize(opts={})
|
18
|
+
Plangrade::Configurable.keys.each do |key|
|
19
|
+
case key
|
20
|
+
when :headers, :connection_options
|
21
|
+
value = Plangrade.instance_variable_get(:"@#{key}").merge(opts.fetch(key, {}))
|
22
|
+
else
|
23
|
+
value = opts.fetch(key, Plangrade.instance_variable_get(:"@#{key}"))
|
24
|
+
end
|
25
|
+
instance_variable_set(:"@#{key}", value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# makes a GET request
|
30
|
+
def get(path, params={})
|
31
|
+
request(:get, path, params)
|
32
|
+
end
|
33
|
+
|
34
|
+
# makes a PUT request
|
35
|
+
def put(path, params={})
|
36
|
+
request(:put, path, params)
|
37
|
+
end
|
38
|
+
|
39
|
+
# makes a POST request
|
40
|
+
def post(path, params={})
|
41
|
+
request(:post, path, params)
|
42
|
+
end
|
43
|
+
|
44
|
+
# makes a DELETE request
|
45
|
+
def delete(path, params={})
|
46
|
+
request(:delete, path, params)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# returns an instance of the http adapter
|
52
|
+
# if none is specified, the default is Plangrade::HttpConnection
|
53
|
+
# @!visibility private
|
54
|
+
def http_client
|
55
|
+
@http_client ||= @http_adapter.new(@site_url, @connection_options)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Makes an HTTP request using the provided parameters
|
59
|
+
# @raise [Plangrade::Error::Unauthorized]
|
60
|
+
# @param method [string]
|
61
|
+
# @param path [string]
|
62
|
+
# @param params [Hash]
|
63
|
+
# @return [Plangrade::ApiResponse]
|
64
|
+
# @!visibility private
|
65
|
+
def request(method, path, params={})
|
66
|
+
headers = @default_headers.merge({'Authorization' => "Bearer #{@access_token}"})
|
67
|
+
result = http_client.send_request(method, path, {
|
68
|
+
:params => params,
|
69
|
+
:headers => headers
|
70
|
+
})
|
71
|
+
result
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'plangrade/http_adapter'
|
2
|
+
|
3
|
+
module Plangrade
|
4
|
+
module Configurable
|
5
|
+
|
6
|
+
ENDPOINT = 'https://plangrade.com' unless defined? ENDPOINT
|
7
|
+
HTTP_ADAPTER = Plangrade::HttpAdapter unless defined? HTTP_CONNECTION
|
8
|
+
|
9
|
+
attr_accessor :client_id, :client_secret, :access_token, :site_url,
|
10
|
+
:connection_options, :default_headers, :http_adapter
|
11
|
+
|
12
|
+
# Return a hash with the default options
|
13
|
+
# @return [Hash]
|
14
|
+
def self.default_options
|
15
|
+
{
|
16
|
+
:site_url => ENDPOINT,
|
17
|
+
:client_id => ENV['PLANGRADE_CLIENT_ID'],
|
18
|
+
:client_secret => ENV['PLANGRADE_CLIENT_SECRET'],
|
19
|
+
:access_token => ENV['PLANGRADE_ACCESS_TOKEN'],
|
20
|
+
:http_adapter => HTTP_ADAPTER,
|
21
|
+
:connection_options => { :max_redirects => 5, :verify_ssl => true },
|
22
|
+
:default_headers => {
|
23
|
+
'Accept' => 'application/json',
|
24
|
+
'User-Agent' => "Plangrade Ruby Gem #{Plangrade::Version}"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Array<String>]
|
30
|
+
def self.keys
|
31
|
+
self.default_options.keys
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Hash]
|
35
|
+
def options
|
36
|
+
Hash[Plangrade::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset!
|
40
|
+
Plangrade::Configurable.keys.each do |key|
|
41
|
+
instance_variable_set(:"@#{key}", Plangrade::Configurable.default_options[key.to_sym])
|
42
|
+
end
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
# Convenience method to allow configuration options to be set in a block
|
47
|
+
def configure
|
48
|
+
yield self if block_given?
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def enable_logging(output='stdout')
|
53
|
+
self.http_adapter.log = output
|
54
|
+
end
|
55
|
+
|
56
|
+
def disable_logging
|
57
|
+
self.http_adapter.log = nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def with_logging(output)
|
61
|
+
cached_output = self.http_adapter.log
|
62
|
+
enable_logging(output)
|
63
|
+
yield self if block_given?
|
64
|
+
self.http_adapter.log = cached_output
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|