puzzle 0.1.0 → 0.2.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.
- data/VERSION +1 -1
- data/lib/puzzle/company.rb +4 -0
- data/lib/puzzle/const.rb +14 -0
- data/lib/puzzle/contact.rb +8 -0
- data/lib/puzzle/error.rb +11 -0
- data/lib/puzzle/exception.rb +14 -0
- data/lib/puzzle/request.rb +55 -2
- data/puzzle.gemspec +4 -1
- metadata +5 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/puzzle/company.rb
CHANGED
@@ -13,6 +13,10 @@ module Puzzle
|
|
13
13
|
@active_contacts = company_info["activeContacts"]
|
14
14
|
end
|
15
15
|
|
16
|
+
# Return a list of companies
|
17
|
+
# => pageSize: The attribute specifies the maximum number of records to be returned in a request. The default value is 50 and the system limit is 100.
|
18
|
+
# => name: Name of the desired company (indexed to include Company Name, URL, and ticker symbol)
|
19
|
+
# => View http://developer.jigsaw.com/documentation/search_and_get_api_guide/6_Data_Keys_and_Values for available search parameter
|
16
20
|
def self.find(options)
|
17
21
|
companies = []
|
18
22
|
result = Puzzle::Request.get("/searchCompany", options)
|
data/lib/puzzle/const.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Puzzle
|
2
|
+
module ErrorCode
|
3
|
+
PARAM_ERROR = "PARAM_ERROR"
|
4
|
+
LOGIN_FAIL = "LOGIN_FAIL"
|
5
|
+
TOKEN_FAIL = "TOKEN_FAIL"
|
6
|
+
PURCHASE_LOW_POINTS = "PURCHASE_LOW_POINTS"
|
7
|
+
CONTACT_NOT_EXIST = "CONTACT_NOT_EXIS"
|
8
|
+
CONTACT_NOT_OWNED = "CONTACT_NOT_OWNED"
|
9
|
+
SEARCH_ERROR = "SEARCH_ERROR"
|
10
|
+
SYS_ERROR = "SYS_ERROR"
|
11
|
+
NOT_IMPLEMENTED = "NOT_IMPLEMENTED"
|
12
|
+
NOT_AVAILABLE = "NOT_AVAILABLE"
|
13
|
+
end
|
14
|
+
end
|
data/lib/puzzle/contact.rb
CHANGED
@@ -43,6 +43,14 @@ module Puzzle
|
|
43
43
|
@owned_type = contact_info["ownedType"]
|
44
44
|
end
|
45
45
|
|
46
|
+
# Return a list of contacts
|
47
|
+
# => pageSize: The attribute specifies the maximum number of records to be returned in a request. The system limit and default value is 500.
|
48
|
+
# => firstname: firstname of the contact to be searched
|
49
|
+
# => lastname: last (or family) name of the contact to be searched
|
50
|
+
# => levels: employee rank (e.g. VP, Staff)
|
51
|
+
# => companyName: company for whom contact works (indexed to include Company Name, URL, and ticker symbol)
|
52
|
+
# => email: full email address of the contact to be searched
|
53
|
+
# => View http://developer.jigsaw.com/documentation/search_and_get_api_guide/6_Data_Keys_and_Values for available search parameter
|
46
54
|
def self.find(options)
|
47
55
|
contacts = []
|
48
56
|
result = Puzzle::Request.get("/searchContact", options)
|
data/lib/puzzle/error.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module Puzzle
|
2
|
+
class Error
|
3
|
+
attr_accessor :stack_trace, :code, :message, :http_status_code
|
4
|
+
def initialize(error)
|
5
|
+
@code = error["errorCode"]
|
6
|
+
@message = error["errorMsg"]
|
7
|
+
@stack_trace = error["stackTrace"]
|
8
|
+
@http_status_code = error["httpStatusCode"]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Puzzle
|
2
|
+
module Exception
|
3
|
+
class ParamError < StandardError; end
|
4
|
+
class LoginFail < StandardError; end
|
5
|
+
class TokenFail < StandardError; end
|
6
|
+
class PurchaseLowPoints < StandardError; end
|
7
|
+
class ContactNotExist < StandardError; end
|
8
|
+
class ContactNotOwned < StandardError; end
|
9
|
+
class SearchError < StandardError; end
|
10
|
+
class SysError < StandardError; end
|
11
|
+
class NotImplemented < StandardError; end
|
12
|
+
class NotAvailable < StandardError; end
|
13
|
+
end
|
14
|
+
end
|
data/lib/puzzle/request.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'exception')
|
2
|
+
require File.join(File.dirname(__FILE__), 'error')
|
3
|
+
require File.join(File.dirname(__FILE__), 'const')
|
1
4
|
require "json"
|
2
5
|
require "cgi"
|
3
6
|
require "net/http"
|
@@ -30,8 +33,7 @@ module Puzzle
|
|
30
33
|
# TODO: Support XML format
|
31
34
|
end
|
32
35
|
else
|
33
|
-
|
34
|
-
false
|
36
|
+
handle_error(response.body, format)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
@@ -55,6 +57,57 @@ module Puzzle
|
|
55
57
|
"#{CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack("H*") }}=#{CGI.escape(value.to_s)}"
|
56
58
|
}.join("&")
|
57
59
|
end
|
60
|
+
|
61
|
+
def self.handle_error(error_body, format = "json")
|
62
|
+
error = parse_error(error_body, format)
|
63
|
+
case error.http_status_code
|
64
|
+
when 400
|
65
|
+
raise Puzzle::Exception::ParamError, error.message
|
66
|
+
when 403
|
67
|
+
case error.code
|
68
|
+
when Puzzle::ErrorCode::LOGIN_FAIL
|
69
|
+
raise Puzzle::Exception::LoginFail, error.message
|
70
|
+
when Puzzle::ErrorCode::TOKEN_FAIL
|
71
|
+
raise Puzzle::Exception::TokenFail, error.message
|
72
|
+
end
|
73
|
+
when 404
|
74
|
+
raise Puzzle::Exception::ContactNotExist, error.message
|
75
|
+
when 405
|
76
|
+
case error.code
|
77
|
+
when Puzzle::ErrorCode::CONTACT_NOT_OWNED
|
78
|
+
raise Puzzle::Exception::ContactNotOwned, error.message
|
79
|
+
when Puzzle::ErrorCode::PURCHASE_LOW_POINTS
|
80
|
+
raise Puzzle::Exception::PurchaseLowPoints, error.message
|
81
|
+
end
|
82
|
+
when 500
|
83
|
+
case error.code
|
84
|
+
when Puzzle::ErrorCode::SEARCH_ERROR
|
85
|
+
raise Puzzle::Exception::SearchError, error.message
|
86
|
+
when Puzzle::ErrorCode::SYS_ERROR
|
87
|
+
raise Puzzle::Exception::SysError, error.message
|
88
|
+
end
|
89
|
+
when 501
|
90
|
+
raise Puzzle::Exception::NotImplemented, error.message
|
91
|
+
when 503
|
92
|
+
raise Puzzle::Exception::NotAvailable, error.message
|
93
|
+
else
|
94
|
+
raise StandardError, "Unknown Error"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.parse_error(error_data, format = "json")
|
99
|
+
error = nil
|
100
|
+
case format
|
101
|
+
when "json"
|
102
|
+
parsed_error = JSON.parse(error_data)
|
103
|
+
if parsed_error && parsed_error.length > 0
|
104
|
+
error = Error.new(parsed_error[0])
|
105
|
+
end
|
106
|
+
when "xml"
|
107
|
+
# TODO: Add xml support
|
108
|
+
end
|
109
|
+
error
|
110
|
+
end
|
58
111
|
end
|
59
112
|
end
|
60
113
|
|
data/puzzle.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "puzzle"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Simon Gingras"]
|
@@ -26,7 +26,10 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/puzzle.rb",
|
27
27
|
"lib/puzzle/company.rb",
|
28
28
|
"lib/puzzle/configuration.rb",
|
29
|
+
"lib/puzzle/const.rb",
|
29
30
|
"lib/puzzle/contact.rb",
|
31
|
+
"lib/puzzle/error.rb",
|
32
|
+
"lib/puzzle/exception.rb",
|
30
33
|
"lib/puzzle/request.rb",
|
31
34
|
"puzzle.gemspec",
|
32
35
|
"test/helper.rb",
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: puzzle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Simon Gingras
|
@@ -86,7 +86,10 @@ files:
|
|
86
86
|
- lib/puzzle.rb
|
87
87
|
- lib/puzzle/company.rb
|
88
88
|
- lib/puzzle/configuration.rb
|
89
|
+
- lib/puzzle/const.rb
|
89
90
|
- lib/puzzle/contact.rb
|
91
|
+
- lib/puzzle/error.rb
|
92
|
+
- lib/puzzle/exception.rb
|
90
93
|
- lib/puzzle/request.rb
|
91
94
|
- puzzle.gemspec
|
92
95
|
- test/helper.rb
|
@@ -104,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
107
|
requirements:
|
105
108
|
- - ">="
|
106
109
|
- !ruby/object:Gem::Version
|
107
|
-
hash:
|
110
|
+
hash: -4390695954410806016
|
108
111
|
segments:
|
109
112
|
- 0
|
110
113
|
version: "0"
|