relink_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: f6b94dada4335f7ba75870ce8e662dfcb937284d
4
+ data.tar.gz: f4d26df2d27e6d20c12933fae8ab783bc88c7044
5
+ SHA512:
6
+ metadata.gz: dd84b803424d6a3032d305fa2ac93ee01be84160e5638accd420bc11502249b362f38d24f32eb97ecbc31463136782b65d3e90c3b9bef00df00ec1da78e6e736
7
+ data.tar.gz: a7bb139bcc655abf720fdc641f224df3da13bc251eee8e07ceffe35db1821421abd9843d786b6d435fb81b72fd4e1aa4196e5e17ba1e3752a00e4b1820a9b5ac
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in relink_marlowe_api.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Andriy Lukashchuk
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.
@@ -0,0 +1,41 @@
1
+ # RelinkMarloweApi
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/relink_marlowe_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'relink_marlowe_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install relink_marlowe_api
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/relink_marlowe_api.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -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 "relink_api"
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,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,19 @@
1
+ class Hash
2
+
3
+ def deep_stringify_keys
4
+ inject({}) do |hash, (key, value)|
5
+ value = value.stringify_keys if value.is_a?(Hash)
6
+ hash[key.to_s] = value
7
+ hash
8
+ end
9
+ end
10
+
11
+ def deep_camelize_keys
12
+ inject({}) do |hash, (key, value)|
13
+ value = value.is_a?(Hash) ? value.deep_camelize_keys : value
14
+ hash[key.to_s.camelizify] = value
15
+ hash
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,10 @@
1
+ class String
2
+
3
+ def camelizify(lower=true)
4
+ self.split('_').map.with_index do |val, index|
5
+ val = val.capitalize if index > 0 && lower
6
+ val
7
+ end.join
8
+ end
9
+
10
+ end
@@ -0,0 +1,61 @@
1
+ require "extensions/string"
2
+ require "extensions/hash"
3
+
4
+ require "relink_api/version"
5
+ require "relink_api/configuration"
6
+ require "relink_api/client"
7
+ require "relink_api/jobs"
8
+ require "relink_api/social"
9
+ require "relink_api/analyze"
10
+ require "relink_api/exceptions"
11
+
12
+ module RelinkApi
13
+
14
+ def self.authenticate
15
+ raise MissingAPICredentials unless self.config
16
+ self.config.api_key &&
17
+ self.config.api_secret &&
18
+ self.config.account_id
19
+
20
+ self.client.authenticate
21
+ end
22
+
23
+ def self.authentication_header
24
+ raise NotAuthorized unless client.token
25
+
26
+ { "Authorization" => "Bearer #{client.token}",
27
+ "Content-Type" => "application/json",
28
+ "Accept" => "application/json" }
29
+ end
30
+
31
+ def self.client
32
+ @client ||= Client.new
33
+ @client
34
+ end
35
+
36
+ protected
37
+
38
+ def self.check_params_presence(present:, required:)
39
+ required.each do |key|
40
+ raise "#{key} key missing" unless present.has_key?(key)
41
+ end
42
+ end
43
+
44
+ def self.camelize_params(params)
45
+ new_params = {}
46
+
47
+ params.each do |key, value|
48
+ new_value = value.is_a?(Hash) ? camelize_params(value) : value
49
+ new_params[key.to_s.camelizify] = new_value
50
+ end
51
+
52
+ new_params
53
+ end
54
+
55
+ def self.transform_params(params)
56
+ params.merge({"accountId": RelinkApi.config.account_id})
57
+ .deep_stringify_keys
58
+ .deep_camelize_keys
59
+ end
60
+
61
+ end
@@ -0,0 +1,29 @@
1
+ # Methods for working with AnAlyze
2
+ # API docs: https://docs.relinklabs.com/marlowe/#Analyze
3
+ require 'httparty'
4
+
5
+ module RelinkApi
6
+ module Analyze
7
+
8
+ CREATE_REQUIRED_PARAMS = %w(jobId profile)
9
+ CREATE_PROFILE_REQUIRED_PARAMS = %w(name summary positions
10
+ email skills educations)
11
+
12
+ CREATE_URL = "/analyze".freeze
13
+
14
+ def self.create(params = {})
15
+ params = RelinkApi.transform_params(params)
16
+
17
+ RelinkApi.check_params_presence(present: params,
18
+ required: CREATE_REQUIRED_PARAMS)
19
+
20
+ RelinkApi.check_params_presence(present: params['profile'],
21
+ required: CREATE_PROFILE_REQUIRED_PARAMS)
22
+
23
+ HTTParty.post(RelinkApi.config.api_base_url + CREATE_URL,
24
+ body: params.to_json,
25
+ headers: RelinkApi.authentication_header)
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ require "base64"
2
+ require "httparty"
3
+
4
+ module RelinkApi
5
+
6
+ class Client
7
+
8
+ attr_reader :token
9
+
10
+ def authenticate
11
+ raise MissingAPICredentials unless RelinkApi.config.api_key &&
12
+ RelinkApi.config.api_secret
13
+
14
+ response = HTTParty.get(RelinkApi.config.api_base_url + "/token",
15
+ headers: authentication_header)
16
+
17
+ if response.code == 200
18
+ body = JSON.parse(response.body)
19
+ @token = body['token']
20
+ else
21
+ raise AuthenticationError
22
+ end
23
+
24
+ end
25
+
26
+ private
27
+
28
+ def authentication_header
29
+ plain_string = RelinkApi.config.api_key + ':' +
30
+ RelinkApi.config.api_secret
31
+ b64_string = Base64.strict_encode64(plain_string)
32
+
33
+ {"Authorization" => "Basic #{b64_string}"}
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,26 @@
1
+ module RelinkApi
2
+
3
+ API_BASE_URL = "http://marlowe.relinklabs.com".freeze
4
+
5
+ class << self
6
+ attr_accessor :config
7
+ end
8
+
9
+ def self.configure
10
+ self.config ||= Configuration.new
11
+ yield(config)
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :api_key
16
+ attr_accessor :api_secret
17
+ attr_accessor :api_base_url
18
+ attr_accessor :notification_url
19
+ attr_accessor :account_id
20
+
21
+ def initialize
22
+ @api_base_url = API_BASE_URL
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,15 @@
1
+ module RelinkApi
2
+
3
+ class MissingAPICredentials < StandardError
4
+ end
5
+
6
+ class AuthenticationError < StandardError
7
+ end
8
+
9
+ class NotAuthorized < StandardError
10
+ end
11
+
12
+ class MissingParams < StandardError
13
+ end
14
+
15
+ end
@@ -0,0 +1,53 @@
1
+ # Methods for working with Jobs
2
+ # API docs: https://docs.relinklabs.com/marlowe/#Jobs
3
+ require 'httparty'
4
+
5
+ module RelinkApi
6
+ module Jobs
7
+
8
+ CREATE_REQUIRED_PARAMS = %w(accountId companyName companyUrl
9
+ title description location)
10
+ CREATE_LOCATION_PARAMS = %w(name cc coords)
11
+ CREATE_COORDS_PARAMS = %w(lat lon)
12
+
13
+ CREATE_URL = "/jobs"
14
+ INDEX_URL = "/jobs"
15
+ SHOW_URL = "/jobs/"
16
+ DELETE_URL = "/jobs/"
17
+
18
+ def self.create(params = {})
19
+ params = RelinkApi.transform_params(params)
20
+
21
+ RelinkApi.check_params_presence(present: params,
22
+ required: CREATE_REQUIRED_PARAMS)
23
+ RelinkApi.check_params_presence(present: params["location"],
24
+ required: CREATE_LOCATION_PARAMS)
25
+ RelinkApi.check_params_presence(present: params["location"]["coords"],
26
+ required: CREATE_COORDS_PARAMS)
27
+
28
+
29
+ HTTParty.post(RelinkApi.config.api_base_url + CREATE_URL,
30
+ body: params.to_json,
31
+ headers: RelinkApi.authentication_header)
32
+ end
33
+
34
+ def self.index(params = {})
35
+ params = RelinkApi.transform_params(params)
36
+
37
+ HTTParty.get(RelinkApi.config.api_base_url + INDEX_URL,
38
+ query: params,
39
+ headers: RelinkApi.authentication_header)
40
+ end
41
+
42
+ def self.show(id)
43
+ HTTParty.get(RelinkApi.config.api_base_url + SHOW_URL + id,
44
+ headers: RelinkApi.authentication_header)
45
+ end
46
+
47
+ def self.delete(id)
48
+ HTTParty.get(RelinkApi.config.api_base_url + DELETE_URL + id,
49
+ headers: RelinkApi.authentication_header)
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,16 @@
1
+ # Methods for working with Social
2
+ # API docs: https://docs.relinklabs.com/marlowe/#Social
3
+ require 'httparty'
4
+
5
+ module RelinkApi
6
+ module Social
7
+
8
+ GET_URL = "/social".freeze
9
+
10
+ def self.show(email:)
11
+ HTTParty.get(RelinkApi.config.api_base_url + GET_URL + "?email=" + email,
12
+ headers: RelinkApi.authentication_header)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module RelinkApi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'relink_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "relink_api"
8
+ spec.version = RelinkApi::VERSION
9
+ spec.authors = ["Andriy Lukashchuk"]
10
+ spec.email = ["darksundarksun@gmail.com"]
11
+
12
+ spec.summary = %q{Relink Marlowe API wrapper.}
13
+ spec.description = %q{Relink Marlowe API wrapper https://relinklabs.com.}
14
+ spec.homepage = "https://github.com/Dark-Sun/relink_api"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_runtime_dependency 'httparty', '~> 0.13.7'
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.13"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "webmock", '~> 0'
39
+ spec.add_development_dependency "factory_girl", '~> 0'
40
+ spec.add_development_dependency "faker", '~> 0'
41
+ spec.add_development_dependency "pry", '~> 0'
42
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relink_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andriy Lukashchuk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_girl
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faker
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Relink Marlowe API wrapper https://relinklabs.com.
126
+ email:
127
+ - darksundarksun@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - lib/extensions/hash.rb
142
+ - lib/extensions/string.rb
143
+ - lib/relink_api.rb
144
+ - lib/relink_api/analyze.rb
145
+ - lib/relink_api/client.rb
146
+ - lib/relink_api/configuration.rb
147
+ - lib/relink_api/exceptions.rb
148
+ - lib/relink_api/jobs.rb
149
+ - lib/relink_api/social.rb
150
+ - lib/relink_api/version.rb
151
+ - relink_marlowe_api.gemspec
152
+ homepage: https://github.com/Dark-Sun/relink_api
153
+ licenses:
154
+ - MIT
155
+ metadata:
156
+ allowed_push_host: https://rubygems.org
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.5.1
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: Relink Marlowe API wrapper.
177
+ test_files: []