spear-cb-api 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c347867ceceb0398580e288d134eb2aa2b3e9c4a
4
+ data.tar.gz: 7d488d3e2419fb71060740d8a5f8b6cf25e94942
5
+ SHA512:
6
+ metadata.gz: 5350b889086c8cbadea37283ac9507dfbc6c43e1d965246a53e4ea0bb03c08f51447c296b22556161a7227a2ba1cf112fdc0cb1534a0c489908c8cf102d452d4
7
+ data.tar.gz: 978e149c92640f48eb988ff4a09f8ab072aa6f920c17bc5f8fe9c11faef7314c0861340315db137a07e5f8b79bad0c63aec645c49217ab77f701a8352715edbc
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/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
4
+ --seed 123456
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spear-cb-api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 CBluowei
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
+ # Spear Cb Api
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'spear-cb-api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install spear-cb-api
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/spear-cb-api/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,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/spear.rb ADDED
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require "spear/version"
4
+
5
+ module Spear
6
+ autoload :AsyncJob, 'spear/async_job'
7
+ autoload :Client, 'spear/client'
8
+ autoload :Request, 'spear/request'
9
+
10
+ # exception
11
+ autoload :InvalidClientOptionsException, 'spear/exceptions'
12
+
13
+ module Resource
14
+ autoload :User, 'spear/resource/user'
15
+ autoload :Resume, 'spear/resource/resume'
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ module Spear
4
+ class AsyncJob
5
+ include SuckerPunch::Job
6
+
7
+ def perform(options={})
8
+ # TODO: save the error to log
9
+ HTTParty.post(
10
+ %q{http://ciws.hilotus.com/api/v1/api-info},
11
+ :body => {
12
+ :project => options[:project],
13
+ :url => options[:url],
14
+ :method => options[:method],
15
+ :request => options[:request],
16
+ :response => options[:response],
17
+ :duration => options[:duration]
18
+ }.to_json,
19
+ :options => {:headers => {'Content-Type' => 'application/json'}}
20
+ ) rescue options
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+
3
+ module Spear
4
+ class Client
5
+ include Spear::Resource::User
6
+ include Spear::Resource::Resume
7
+
8
+ attr_reader :options, :request
9
+
10
+ def initialize(options={})
11
+ raise Spear::InvalidClientOptionsException.new('DeveloperKey is missing!') if options[:dev_key].nil?
12
+ raise Spear::InvalidClientOptionsException.new('ProjectName is missing!') if options[:project].nil?
13
+
14
+ @options = options
15
+ @request = generate_request
16
+ end
17
+
18
+ def test?
19
+ @options[:use_test] || false
20
+ end
21
+
22
+ # use https or http
23
+ def ssh?
24
+ @options[:use_ssh] || true
25
+ end
26
+
27
+ def hostname
28
+ @options[:hostname] || 'api.careerbuilder.com'
29
+ end
30
+
31
+ def port
32
+ @options[:port] || 443
33
+ end
34
+
35
+ def version
36
+ @options[:version] || "v2"
37
+ end
38
+
39
+ def dev_key
40
+ @options[:dev_key]
41
+ end
42
+
43
+ # need save api info
44
+ def save_api?
45
+ @options[:use_saving_api] || false
46
+ end
47
+
48
+ def project
49
+ @options[:project]
50
+ end
51
+
52
+ private
53
+ def generate_request(options={})
54
+ options = {:client => self}.merge(options)
55
+ return Spear::Request.new(options)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Spear
2
+ class InvalidClientOptionsException < Exception; end
3
+ end
@@ -0,0 +1,76 @@
1
+ module Spear
2
+ class Request
3
+ attr_reader :client, :resource
4
+
5
+ def initialize(options={})
6
+ @client = options[:client]
7
+ @resource = resource
8
+ @async_job = Spear::AsyncJob.new
9
+ end
10
+
11
+ # TODO: custom reqeust headers support.
12
+ # payload: {:body => {}, :query => {}}
13
+ def execute(http_method, endpoint, payload={})
14
+ start_time = Time.now;
15
+ url = @resource + endpoint;
16
+
17
+ case http_method
18
+ when :get
19
+ req = splice(payload)
20
+ resp = HTTParty.get(url, req)
21
+ when :post
22
+ req = {:body => to_xml(payload)}
23
+ resp = HTTParty.post(url, req)
24
+ when :upload_file
25
+ req = splice(payload)
26
+ req[:body] = "file base64 content..."
27
+ resp = HTTParty.post(url, splice(payload))
28
+ when :parse_file
29
+ req = {:body => payload}
30
+ req[:body][:FileBytes] = nil
31
+ resp = HTTParty.post(url, :body => to_xml(payload))
32
+ else
33
+ resp = {"Errors" => {"Error" => "%q{#{http_method} http method is not support.}"}}
34
+ end
35
+
36
+ if @client.save_api?
37
+ options = {
38
+ project: @client.project,
39
+ request: req,
40
+ response: resp.to_h,
41
+ method: http_method.to_s,
42
+ url: url,
43
+ duration: ((Time.now - start_time).to_f * 1000.0).to_i
44
+ }
45
+ @async_job.async.perform(options)
46
+ end
47
+
48
+ resp
49
+ end
50
+
51
+ private
52
+ def resource
53
+ uri = URI("")
54
+ uri.scheme = @client.ssh? ? 'https' : 'http'
55
+ uri.host = @client.hostname
56
+ uri.port = @client.port
57
+ uri.path = "/#{@client.version}"
58
+ uri.to_s
59
+ end
60
+
61
+ # parse payload to xml format
62
+ def to_xml(payload)
63
+ payload[:DeveloperKey] = @client.dev_key
64
+ payload[:Test] = @client.test?
65
+ payload = payload.to_xml(root: 'Request', skip_instruct: true, skip_types: true)
66
+ end
67
+
68
+ # splice payload {:body => {}, :query => {}} with DeveloperKey and Test
69
+ def splice(payload)
70
+ payload[:query][:DeveloperKey] = @client.dev_key
71
+ payload[:query][:Test] = @client.test?
72
+ payload
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+
3
+ module Spear
4
+ module Resource
5
+ module Resume
6
+ # file: kind of ActionDispatch::Http::UploadedFile
7
+ def parse_file(file)
8
+ unless (file.kind_of? ActionDispatch::Http::UploadedFile) || (file.kind_of? Rack::Test::UploadedFile)
9
+ return {"Errors" => {"Error" => "%q{Expecting type of ActionDispatch::Http::UploadedFile or Rack::Test::UploadedFile, but got #{file.class}.}"}}
10
+ end
11
+
12
+ file.rewind
13
+ @request.execute(:parse_file, "/resume/parse", {:FileName => file.original_filename,
14
+ :FileBytes => Base64.encode64(file.read)})
15
+ end
16
+
17
+ # Required column value
18
+ # <ShowContactInfo>true</ShowContactInfo>
19
+ # <Title>asasdasdasd</Title>
20
+ # <ResumeText>albee009@gmail.com JobsCentral999</ResumeText>
21
+ # <Visibility>true</Visibility>
22
+ # <CanRelocateNationally>false</CanRelocateNationally>
23
+ # <CanRelocateInternationally>false</CanRelocateInternationally>
24
+ # <TotalYearsExperience>0</TotalYearsExperience>
25
+ # <HostSite>T3</HostSite>
26
+ # <DesiredJobTypes>ETFE</DesiredJobTypes>
27
+ # <CompanyExperiences/>
28
+ # <Educations/>
29
+ # <Languages/>
30
+ # <CustomValues/>
31
+ def create_resume(data={})
32
+ @request.execute(:post, "/resume/create", data)
33
+ end
34
+
35
+ def upload_file(file, resume_external_id, user_external_id)
36
+ unless (file.kind_of? ActionDispatch::Http::UploadedFile) || (file.kind_of? Rack::Test::UploadedFile)
37
+ return {"Errors" => {"Error" => "%q{Expecting type of ActionDispatch::Http::UploadedFile or Rack::Test::UploadedFile, but got #{file.class}.}"}}
38
+ end
39
+
40
+ if user_external_id.blank? or resume_external_id.blank?
41
+ return {"Errors" => {"Error" => "%q{User external ID and resume external ID is required.}"}}
42
+ end
43
+
44
+ file.rewind
45
+ @request.execute(:upload_file, "/resume/upload", {
46
+ :body => Base64.encode64(file.read),
47
+ :query => {
48
+ :FileName => file.original_filename,
49
+ :ExternalID => resume_external_id,
50
+ :ExternalUserID => user_external_id
51
+ }
52
+ })
53
+ end
54
+
55
+ # list all of my resumes
56
+ def own_all(user_external_id, host_site)
57
+ if user_external_id.blank? or host_site.blank?
58
+ return {"Errors" => {"Error" => "%q{User external ID and host site is required.}"}}
59
+ end
60
+
61
+ @request.execute(:get, "/resume/ownall", {
62
+ :query => {:ExternalUserID => user_external_id, :HostSite => host_site}})
63
+ end
64
+
65
+ def retrieve_resume(resume_external_id, user_external_id)
66
+ if user_external_id.blank? or resume_external_id.blank?
67
+ return {"Errors" => {"Error" => "%q{User external ID and host site is required.}"}}
68
+ end
69
+
70
+ @request.execute(:get, "/resume/retrieve", {
71
+ :query => {:ExternalUserID => user_external_id, :ExternalID => resume_external_id}})
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ module Spear
4
+ module Resource
5
+ module User
6
+ def check_existing(email, password='')
7
+ if password.blank?
8
+ @request.execute(:post, "/user/checkexisting", {:Email => email})
9
+ else
10
+ @request.execute(:post, "/user/checkexisting", {:Email => email, :Password => password})
11
+ end
12
+ end
13
+
14
+ def create_user(data={})
15
+ @request.execute(:post, "/user/create", data)
16
+ end
17
+
18
+ def retrieve_user(user_external_id, password)
19
+ @request.execute(:post, "/user/retrieve", {:ExternalID => user_external_id, :Password => password})
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Spear
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spear/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spear-cb-api"
8
+ spec.version = Spear::VERSION
9
+ spec.authors = ["CBluowei"]
10
+ spec.email = ["wei.luo@careerbuilder.com"]
11
+ spec.summary = %q{Cb api wrapper}
12
+ spec.description = %q{This gem include api wrapper, response structure and dummy data.}
13
+ spec.homepage = "https://github.com/hilotus/spear-cb-api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "sucker_punch", "~> 1.0"
22
+ spec.add_development_dependency "rspec", "~> 3.2", ">= 3.2.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake", "~> 10.4"
26
+ end
@@ -0,0 +1,5 @@
1
+ describe Spear::Client do
2
+ it "check user existing" do
3
+
4
+ end
5
+ end
@@ -0,0 +1,70 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'spear' # and any other gems you need
5
+
6
+ RSpec.configure do |config|
7
+ # config.include Capybara::DSL,:type=>:request
8
+ # The settings below are suggested to provide a good initial experience
9
+ # with RSpec, but feel free to customize to your heart's content.
10
+ #=begin
11
+ # These two settings work together to allow you to limit a spec run
12
+ # to individual examples or groups you care about by tagging them with
13
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
14
+ # get run.
15
+ # config.filter_run :focus
16
+ # config.run_all_when_everything_filtered = true
17
+
18
+ # Many RSpec users commonly either run the entire suite or an individual
19
+ # file, and it's useful to allow more verbose output when running an
20
+ # individual spec file.
21
+ # if config.files_to_run.one?
22
+ # Use the documentation formatter for detailed output,
23
+ # unless a formatter has already been configured
24
+ # (e.g. via a command-line flag).
25
+ # config.default_formatter = 'doc'
26
+ # end
27
+
28
+ # Print the 10 slowest examples and example groups at the
29
+ # end of the spec run, to help surface which specs are running
30
+ # particularly slow.
31
+ config.profile_examples = 10
32
+
33
+ # Run specs in random order to surface order dependencies. If you find an
34
+ # order dependency and want to debug it, you can fix the order by providing
35
+ # the seed, which is printed after each run.
36
+ # --seed 1234
37
+ config.order = :random
38
+
39
+ # Seed global randomization in this process using the `--seed` CLI option.
40
+ # Setting this allows you to use `--seed` to deterministically reproduce
41
+ # test failures related to randomization by passing the same `--seed` value
42
+ # as the one that triggered the failure.
43
+ Kernel.srand config.seed
44
+
45
+ # rspec-expectations config goes here. You can use an alternate
46
+ # assertion/expectation library such as wrong or the stdlib/minitest
47
+ # assertions if you prefer.
48
+ config.expect_with :rspec do |expectations|
49
+ # Enable only the newer, non-monkey-patching expect syntax.
50
+ # For more details, see:
51
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
52
+ expectations.syntax = :expect
53
+
54
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
55
+ end
56
+
57
+ # rspec-mocks config goes here. You can use an alternate test double
58
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
59
+ config.mock_with :rspec do |mocks|
60
+ # Enable only the newer, non-monkey-patching expect syntax.
61
+ # For more details, see:
62
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
63
+ mocks.syntax = :expect
64
+
65
+ # Prevents you from mocking or stubbing a method that does not exist on
66
+ # a real object. This is generally recommended.
67
+ mocks.verify_partial_doubles = true
68
+ end
69
+ #=end
70
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spear-cb-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - CBluowei
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sucker_punch
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 3.2.0
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '3.2'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.2.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.6'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.4'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.4'
75
+ description: This gem include api wrapper, response structure and dummy data.
76
+ email:
77
+ - wei.luo@careerbuilder.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".rspec"
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - lib/spear.rb
89
+ - lib/spear/async_job.rb
90
+ - lib/spear/client.rb
91
+ - lib/spear/exceptions.rb
92
+ - lib/spear/request.rb
93
+ - lib/spear/resource/resume.rb
94
+ - lib/spear/resource/user.rb
95
+ - lib/spear/version.rb
96
+ - spear-cb-api.gemspec
97
+ - spec/client_spec.rb
98
+ - spec/spec_helper.rb
99
+ homepage: https://github.com/hilotus/spear-cb-api
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.2.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Cb api wrapper
123
+ test_files:
124
+ - spec/client_spec.rb
125
+ - spec/spec_helper.rb