hubscreen 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 823f6917ca52e4a446daedd9c2d20ad2951d3897
4
- data.tar.gz: 512507d2bbcd0ab768421c07ab47c2727595e37c
3
+ metadata.gz: 3955eb4b47abd454794b7efd470987e27ef242e9
4
+ data.tar.gz: 52d2bfb0428c18ac01cecf7891ef79ff21239bc1
5
5
  SHA512:
6
- metadata.gz: 4be0336ac9f41fe396a77113312e1697babae7acf78a67621a49dfb255a2e53012f024c6771fac51c0e0b84bf13fc189b5e25f6a8781f81d429223798e099752
7
- data.tar.gz: 7ab4c31b027932cc16dcf6506a3ad57d93558b6b46c13751e980655937c85aee44919385835f26a6edf01e865b9a707e268f5996b2e3aa6afd8e43b933d1bde9
6
+ metadata.gz: 7db3be09776d870ff8961683438066b629e8e0a79ca3b3c02191eb95c7df07e4943e1393ec1dafde135d9a2dda87675e77ef1a2b911092740fae71265a2db08f
7
+ data.tar.gz: 7fe3da303a01cbe7e1a47e9d21f5beb2d33fadffdaee7371d034d220e5944e7362978ec9505749ae671a68ab746419012a0c1ad8f559492dea5194a82e88fc67
data/README.md CHANGED
@@ -43,6 +43,8 @@ The gem is available as open source under the terms of the [MIT License](http://
43
43
 
44
44
  This project and the code therein was not created by and is not supported by HubSpot, Inc or any of its affiliates.
45
45
 
46
+ Hubscreen is provided on an AS-IS basis. Any use of of this code in a business environment should be subjected to additional functional and integration testing prior to release.
47
+
46
48
  ## Copyright
47
49
 
48
50
  Copyright (c) 2016 IMIT Advisory Limited. See LICENSE.txt for further details.
@@ -34,13 +34,14 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency "rspec", "~> 3.5"
35
35
  spec.add_development_dependency "vcr", "~> 3.0"
36
36
  spec.add_development_dependency "webmock", "~> 2.1"
37
-
38
-
37
+
39
38
  #Interactive Testing
40
- spec.add_development_dependency 'pry'
39
+ spec.add_development_dependency 'pry-byebug'
41
40
 
41
+ #Gem Dependancies
42
42
  spec.add_dependency(%q<activesupport>, [">= 5.0.0"])
43
43
  spec.add_dependency('faraday', '>= 0.9.2')
44
44
  spec.add_dependency('multi_json', '>= 1.12.1')
45
+ spec.add_dependency('recursive-open-struct', '>= 1.0')
45
46
 
46
47
  end
@@ -4,10 +4,12 @@ require 'active_support/core_ext'
4
4
  require 'faraday'
5
5
  require 'multi_json'
6
6
  require 'cgi'
7
+ require 'recursive-open-struct'
7
8
 
8
9
  #Rest API Helpers
9
10
  require "hubscreen/api_request"
10
11
  require "hubscreen/request"
12
+ require "hubscreen/response"
11
13
 
12
14
  #Gem Lib Files
13
15
  require "hubscreen/version"
@@ -6,6 +6,7 @@ module Hubscreen
6
6
  # A new API request must pass in a Hubscreen::Request Object
7
7
  def initialize(builder: nil)
8
8
  @request_builder = builder
9
+ @return_encapuslated_object = Hubscreen::Config.encapsulate_response
9
10
  end
10
11
 
11
12
  def post(params: nil, headers: nil, body: nil)
@@ -73,7 +74,7 @@ module Hubscreen
73
74
  end
74
75
  end
75
76
 
76
- #protected
77
+ protected
77
78
 
78
79
  # Convenience accessors
79
80
 
@@ -161,17 +162,20 @@ module Hubscreen
161
162
  raise error
162
163
  end
163
164
  end
164
-
165
- parsed_response
165
+ if @return_encapuslated_object
166
+ return Hubscreen::Response.new(parsed_response)
167
+ else
168
+ return parsed_response
169
+ end
166
170
  end
167
171
 
168
172
  def validate_api_key
169
173
  api_key = self.api_key
170
174
  api_endpoint = self.api_endpoint
171
- unless api_key
175
+ unless !api_key.blank?
172
176
  raise Hubscreen::ApiError, "You must set an api_key prior to making a call"
173
177
  end
174
- unless api_endpoint
178
+ unless !api_endpoint.blank?
175
179
  raise Hubscreen::ApiError, "You must set an api_endpoint prior to making a call"
176
180
  end
177
181
  end
@@ -5,9 +5,10 @@ require 'logger'
5
5
  module Hubscreen
6
6
  class Config
7
7
 
8
- CONFIG_KEYS = [:hapikey, :base_url, :portal_id, :logger]
8
+ CONFIG_KEYS = [:hapikey, :base_url, :portal_id, :logger, :encapsulate_response]
9
9
  DEFAULT_LOGGER = Logger.new(STDOUT)
10
10
  DEFAULT_BASE_URL = "https://api.hubapi.com/"
11
+ DEFAULT_RESPONSE_ENCAPSULATION = true
11
12
 
12
13
  class << self
13
14
  attr_accessor *CONFIG_KEYS
@@ -18,6 +19,7 @@ module Hubscreen
18
19
  @base_url = config["base_url"] || DEFAULT_BASE_URL
19
20
  @portal_id = config["portal_id"] #not currenty used
20
21
  @logger = config['logger'] || DEFAULT_LOGGER
22
+ @encapsulate_response = config['encapsulate_response'] || DEFAULT_RESPONSE_ENCAPSULATION
21
23
  self
22
24
  end
23
25
 
@@ -26,6 +28,7 @@ module Hubscreen
26
28
  @base_url = DEFAULT_BASE_URL
27
29
  @portal_id = nil
28
30
  @logger = DEFAULT_LOGGER
31
+ @encapsulate_response = DEFAULT_RESPONSE_ENCAPSULATION
29
32
  end
30
33
 
31
34
  def ensure!(*params)
@@ -1,11 +1,43 @@
1
+ require 'pry'
1
2
  module Hubscreen
2
3
  #
3
4
  # HubSpot Contacts API
4
5
  #
5
6
  # {https://developers.hubspot.com/docs/methods/contacts/contacts-overview}
6
7
  #
8
+ # This is a convenience object for single Hubspot contact returned by the API
7
9
 
8
- class Contact
10
+ class Contact < Hubscreen::Response
11
+ CONTACT_KEYS = [:properties,
12
+ :vid,
13
+ :email,
14
+ :first_name,
15
+ :last_name,
16
+ :hubspot_owner_id]
17
+
18
+ attr_accessor *CONTACT_KEYS
19
+
20
+ def initialize(response)
21
+ @raw_hash = response.raw_hash
22
+ @raw_response = response.raw_response
23
+ parse_response
24
+ end
25
+
26
+ def parse_response
27
+ @properties = @raw_response.properties
28
+ @vid = @raw_hash["vid"]
29
+ @email = @raw_hash["properties"]["email"]["value"] if @raw_hash["properties"].has_key?("email")
30
+ @first_name = @raw_hash["properties"]["firstname"]["value"] if @raw_hash["properties"].has_key?("firstname")
31
+ @last_name = @raw_hash["properties"]["lastname"]["value"] if @raw_hash["properties"].has_key?("lastname")
32
+ @company = @raw_hash["properties"]["company"]["value"] if @raw_hash["properties"].has_key?("company")
33
+ @hubspot_owner_id = @raw_hash["properties"]["hubspot_owner_id"]["value"] if @raw_hash["properties"].has_key?("hubspot_owner_id")
34
+ end
35
+
36
+ def inspect
37
+ "<Hubscreen::Contact vid:#{@vid}, email:'#{@email}', first_name:'#{@first_name}', last_name:'#{@last_name}', company:'#{@company}', hubspot_owner_id:'#{@hubspot_owner_id}', properties:<Not Shown>, raw_response:<Not Shown>, raw_hash:<Not Shown>>"
38
+ end
39
+
9
40
 
10
41
  end
42
+
11
43
  end
@@ -0,0 +1,28 @@
1
+ module Hubscreen
2
+
3
+ # Hubscreen::Response
4
+ #
5
+ # Parent Class for all Hubscreen response objects. Designed for direct access to the response either through the "raw_hash" which is the hash representation of the JSON response or the "raw_response" which is the OpenStruct representation
6
+ #
7
+ # By default all APIRequests will return a Response object. To disable this, set Hubscreen.configure(encapsulate_response: false)
8
+
9
+ class Response
10
+ attr_accessor :raw_hash, :raw_response
11
+
12
+ def initialize(response_json_hash)
13
+ @raw_hash = response_json_hash
14
+ @raw_response = RecursiveOpenStruct.new(response_json_hash)
15
+ end
16
+
17
+ # Prints out the raw response in formatted JSON.
18
+ # This method is primarily used to aid in debugging
19
+ def pretty_response
20
+ JSON.pretty_generate(@raw_hash)
21
+ end
22
+
23
+ #Type Cast Helpers
24
+ def contact
25
+ Contact.new(self)
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Hubscreen
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubscreen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Vaz
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.1'
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry
84
+ name: pry-byebug
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: 1.12.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: recursive-open-struct
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '1.0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '1.0'
139
153
  description: Multi-purpose Ruby wrapper for the Hubspot CRM API with access to the
140
154
  raw response or Ruby objects for faster development
141
155
  email:
@@ -163,6 +177,7 @@ files:
163
177
  - lib/hubscreen/contact.rb
164
178
  - lib/hubscreen/exceptions.rb
165
179
  - lib/hubscreen/request.rb
180
+ - lib/hubscreen/response.rb
166
181
  - lib/hubscreen/version.rb
167
182
  homepage: https://github.com/bryanvaz/hubscreen
168
183
  licenses: