frederick_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +86 -0
- data/lib/frederick_api/configuration.rb +54 -0
- data/lib/frederick_api/v2/location.rb +8 -0
- data/lib/frederick_api/v2/query_builder.rb +35 -0
- data/lib/frederick_api/v2/resource.rb +25 -0
- data/lib/frederick_api/v2/user.rb +8 -0
- data/lib/frederick_api/version.rb +6 -0
- data/lib/frederick_api.rb +16 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3de672e56c6302f235bed63e48c4dd11978344ea
|
4
|
+
data.tar.gz: 173a72637912e59ae28c5f99eca47d5c6207dfff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 076b3051e48620744b08af1d2aae2571edecb87688341d4b748c92503157d6c46e52c4522c5ac0016a64044fcf9a30440ca31cd8b186e805a6608b1b5e0f5446
|
7
|
+
data.tar.gz: 02b1230c8352a91edda3268866b185e54e4397b2185a0d37eaf896bc64f6b72c8b6d61a976865984db9ef70c66f8a0e77ee244d83e979913b83634f2e2d69698
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2009-2017 Frederick Labs LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
[ ![Codeship Status for BookerSoftwareInc/frederick_api_gem](https://app.codeship.com/projects/43a5ea40-2b13-0135-7e95-4afd89638027/status?branch=master)](https://app.codeship.com/projects/224007)
|
2
|
+
|
3
|
+
```text
|
4
|
+
_____ _ _ _ _ ____ ___
|
5
|
+
| ___| __ ___ __| | ___ _ __(_) ___| | __ / \ | _ \_ _|___
|
6
|
+
| |_ | '__/ _ \/ _` |/ _ \ '__| |/ __| |/ / / _ \ | |_) | |/ __|
|
7
|
+
| _|| | | __/ (_| | __/ | | | (__| < / ___ \| __/| |\__ \
|
8
|
+
|_| |_| \___|\__,_|\___|_| |_|\___|_|\_\ /_/ \_\_| |___|___/
|
9
|
+
```
|
10
|
+
|
11
|
+
|
12
|
+
This gem provides a client for Frederick's V2 APIs.
|
13
|
+
|
14
|
+
Note: Our V2 APIs have not yet been released for use by customers or partners. See
|
15
|
+
[Frederick Developers](https://developers.hirefrederick.com) for supported APIs and documentation.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Put this in your Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'frederick_api'
|
23
|
+
```
|
24
|
+
|
25
|
+
You're now ready to go with Frederick's v2 API!
|
26
|
+
|
27
|
+
### Configuring FrederickAPI
|
28
|
+
|
29
|
+
You can use `FrederickAPI.configure` or environment variables
|
30
|
+
to configure the Frederick API client.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# config/initializers/frederick_api.rb
|
34
|
+
...
|
35
|
+
FrederickAPI.configure do |c|
|
36
|
+
c.base_url = 'https://api.hirefrederick.com'
|
37
|
+
c.api_key = '1234-5678-1234-5678-1234-5678'
|
38
|
+
end
|
39
|
+
...
|
40
|
+
```
|
41
|
+
|
42
|
+
Environment variables can also be used:
|
43
|
+
* `FREDERICK_API_BASE_URL`: Same as `base_url` above
|
44
|
+
* `FREDERICK_API_KEY`: Same as `api_key` above
|
45
|
+
|
46
|
+
Environments:
|
47
|
+
* For testing (default), use `FREDERICK_API_BASE_URL = https://api.staging.hirefrederick.com`
|
48
|
+
* For production, use `FREDERICK_API_BASE_URL = https://api.hirefrederick.com`
|
49
|
+
|
50
|
+
NOTE: You must specify the production base URL of `https://api.hirefrederick.com` in order to use this gem with
|
51
|
+
Frederick's production API.
|
52
|
+
|
53
|
+
## Usage
|
54
|
+
|
55
|
+
Frederick V2 Resources correspond to ([JSON API](http://jsonapi.org/) compatible) APIs and use the
|
56
|
+
[json_api_client](https://github.com/chingor13/json_api_client) gem under the hood, so provide access
|
57
|
+
to standard "ActiveRecord-like" functionaliy such as `.create`, `.find`, `.where`, `.order`, `.includes` to create, find,
|
58
|
+
filter, sort, and include relationships.
|
59
|
+
|
60
|
+
### Access Tokens
|
61
|
+
|
62
|
+
An access token is required to access resources on behalf of a use. Use `Resource.with_access_token { ... }` to make
|
63
|
+
requests with an access token.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
location_id = '6fdf0530-3e4e-46f1-9d11-5f90c48a50dc'
|
67
|
+
access_token = '9jsdo320fjfkfdksls30dfdcd919bcaa1b7804dbbebda0'
|
68
|
+
FrederickAPI::V2::Location.with_access_token(access_token) do
|
69
|
+
# Fetch a location
|
70
|
+
location = FrederickAPI::V2::Location.find(location_id)
|
71
|
+
# => #<FrederickAPI::V2::Location:0x007fd2f29a7618>
|
72
|
+
|
73
|
+
location.name
|
74
|
+
# => 'Bizzy Biz'
|
75
|
+
|
76
|
+
# Update a location
|
77
|
+
location.name = 'Biz Bizziest'
|
78
|
+
location.save
|
79
|
+
# => true
|
80
|
+
|
81
|
+
# To instantiate a resource for update without fetching it first, set an id
|
82
|
+
location = FrederickAPI::V2::Location.new(id: location_id)
|
83
|
+
location.update_attributes(phone_number: '(555) 555-5555')
|
84
|
+
# => true
|
85
|
+
end
|
86
|
+
```
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FrederickAPI # :nodoc:
|
4
|
+
class << self
|
5
|
+
attr_writer :config
|
6
|
+
end
|
7
|
+
|
8
|
+
# You may use `FrederickAPI.configure` to configure the Frederick
|
9
|
+
# Internal API Gem or you can use environment variables. By default, the
|
10
|
+
# client will connect to staging with a blank API key.
|
11
|
+
# @see .configure
|
12
|
+
class Configuration
|
13
|
+
DEFAULTS = {
|
14
|
+
base_url: ENV['FREDERICK_API_BASE_URL'] ||
|
15
|
+
'https://api.staging.hirefrederick.com',
|
16
|
+
api_key: ENV['FREDERICK_API_KEY']
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
attr_accessor :base_url, :api_key
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@base_url = DEFAULTS[:base_url]
|
23
|
+
@api_key = DEFAULTS[:api_key]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Configure FrederickAPI, for example in an initializer or (better
|
28
|
+
# yet) in one of the `config/environments/*.rb` files so you can have it
|
29
|
+
# configured differently per environment. For example, you may want to use
|
30
|
+
# staging API in staging environment, or may want different timeouts in
|
31
|
+
# development environment than production.
|
32
|
+
#
|
33
|
+
# @example
|
34
|
+
# # config/environments/staging.rb
|
35
|
+
# ...
|
36
|
+
# FrederickAPI.configure do |c|
|
37
|
+
# c.base_url = 'https://api.staging.hirefrederick.com/v1'
|
38
|
+
# c.api_key = '1234-5678-1234-5678-1234-5678'
|
39
|
+
# end
|
40
|
+
# ...
|
41
|
+
#
|
42
|
+
# @yield [configuration] block to configure FrederickAPI
|
43
|
+
# @return [FrederickAPI::Configuration] the completed configuration
|
44
|
+
def self.configure
|
45
|
+
yield(config)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns a reference to the current configuration.
|
49
|
+
#
|
50
|
+
# @return [FrederickAPI::Configuration]
|
51
|
+
def self.config
|
52
|
+
@config ||= Configuration.new
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module'
|
4
|
+
|
5
|
+
module FrederickAPI
|
6
|
+
module V2
|
7
|
+
# Used to convert nested params to dot notation for Frederick API
|
8
|
+
class QueryBuilder < JsonApiClient::Query::Builder
|
9
|
+
def params
|
10
|
+
to_dot_params(
|
11
|
+
filter_params.merge(pagination_params.merge(includes_params).merge(select_params))
|
12
|
+
).merge(order_params)
|
13
|
+
.merge(primary_key_params)
|
14
|
+
.merge(path_params)
|
15
|
+
.merge(additional_params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_dot_params(object, prefix = nil)
|
19
|
+
return {} if object == {}
|
20
|
+
|
21
|
+
if object.is_a? Hash
|
22
|
+
object.map do |key, value|
|
23
|
+
if prefix
|
24
|
+
to_dot_params value, "#{prefix}.#{key}"
|
25
|
+
else
|
26
|
+
to_dot_params value, key.to_s
|
27
|
+
end
|
28
|
+
end.reduce(&:merge)
|
29
|
+
else
|
30
|
+
{ prefix => object }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FrederickAPI
|
4
|
+
module V2
|
5
|
+
# Class from which Frederick V2 Resources inherit
|
6
|
+
# Inherits functionality from JsonApiClient::Resource
|
7
|
+
class Resource < JsonApiClient::Resource
|
8
|
+
self.query_builder = FrederickAPI::V2::QueryBuilder
|
9
|
+
|
10
|
+
def self.site
|
11
|
+
"#{FrederickAPI.config.base_url}/v2/"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.with_access_token(token)
|
15
|
+
with_headers(authorization: "Bearer #{token}") do
|
16
|
+
yield
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.custom_headers
|
21
|
+
super.merge(x_api_key: FrederickAPI.config.api_key)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Third-party libs
|
4
|
+
require 'json_api_client'
|
5
|
+
|
6
|
+
# FrederickAPI libs
|
7
|
+
require 'frederick_api/configuration'
|
8
|
+
require 'frederick_api/v2/query_builder'
|
9
|
+
require 'frederick_api/v2/resource'
|
10
|
+
|
11
|
+
require 'frederick_api/v2/user'
|
12
|
+
require 'frederick_api/v2/location'
|
13
|
+
|
14
|
+
# Namespace for all Frederick API client methods/classes
|
15
|
+
module FrederickAPI
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: frederick_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Frederick Engineering
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json_api_client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.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.5.1
|
27
|
+
description: Ruby client for the Frederick API
|
28
|
+
email:
|
29
|
+
- tech@hirefrederick.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- lib/frederick_api.rb
|
37
|
+
- lib/frederick_api/configuration.rb
|
38
|
+
- lib/frederick_api/v2/location.rb
|
39
|
+
- lib/frederick_api/v2/query_builder.rb
|
40
|
+
- lib/frederick_api/v2/resource.rb
|
41
|
+
- lib/frederick_api/v2/user.rb
|
42
|
+
- lib/frederick_api/version.rb
|
43
|
+
homepage: https://github.com/HireFrederick/frederick_api_gem
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.6.11
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Frederick API Client
|
67
|
+
test_files: []
|