contactually 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/contactually/version.rb +1 -1
- data/lib/contactually.rb +29 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2744934fe9ac93c12fb2ce2919ab4c25a15cecf7
|
4
|
+
data.tar.gz: 1211d34bee6b7e0bfd342c83138d7e5c5a5da233
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8ce41005b490e177675b8789f64e3f7c0a6678d0b86614f635871d34b28f84ed90824d83c26c23cb6c4eed207f15bd57ce9127f214be61948670fa9c2a29d13
|
7
|
+
data.tar.gz: fcf8965833261d1e223737a4da533d76b8190fef3822a937865ccb3bc1160fcdab9c0c05252429d0dc7bc1d7ea19babcf30d2afaf3471319482fe2346fe53774
|
data/lib/contactually/version.rb
CHANGED
data/lib/contactually.rb
CHANGED
@@ -4,7 +4,12 @@ require "json"
|
|
4
4
|
module Contactually
|
5
5
|
class API
|
6
6
|
|
7
|
-
|
7
|
+
HTTP_ACTIONS = %w(get post put delete).freeze
|
8
|
+
METHODS = %w(contacts notes groupings).freeze
|
9
|
+
|
10
|
+
attr_reader :http_action, :contactually_method
|
11
|
+
|
12
|
+
def initialize(api_key, headers = {})
|
8
13
|
@api_key = api_key
|
9
14
|
|
10
15
|
# The Contactually API recommends passing in a User-Agent header unique to
|
@@ -18,42 +23,48 @@ module Contactually
|
|
18
23
|
@headers = headers
|
19
24
|
end
|
20
25
|
|
21
|
-
def call(method,
|
22
|
-
parsed_response = make_call(method,
|
23
|
-
|
26
|
+
def call(method, params)
|
27
|
+
if (parsed_response = make_call(method, params))
|
28
|
+
parsed_response
|
29
|
+
else
|
30
|
+
false
|
31
|
+
end
|
24
32
|
end
|
25
33
|
|
26
34
|
def method_missing(method, *args)
|
27
|
-
call(method, args)
|
35
|
+
call(method, args.try(:first) || {})
|
28
36
|
end
|
29
37
|
|
30
38
|
private
|
31
|
-
|
32
|
-
|
33
|
-
params
|
39
|
+
|
40
|
+
def param_fields(params)
|
41
|
+
return params.to_json unless %w(get delete).include?(http_action)
|
34
42
|
params
|
35
43
|
end
|
36
44
|
|
37
|
-
def make_call(
|
38
|
-
|
39
|
-
uri
|
40
|
-
response = Curl.send(
|
45
|
+
def make_call(composite, params = {})
|
46
|
+
return false unless get_methods(composite)
|
47
|
+
uri = build_uri(contactually_method, params)
|
48
|
+
response = Curl.send(http_action.to_sym, uri, param_fields(params)) do |curl|
|
41
49
|
@headers.each do |header_name, header_value|
|
42
50
|
curl.headers[header_name.to_s.titleize.gsub(" ", "-")] = header_value
|
43
51
|
end
|
44
|
-
curl.headers['Accept']
|
52
|
+
curl.headers['Accept'] = 'application/json'
|
45
53
|
curl.headers['Content-Type'] = 'application/json'
|
46
54
|
end
|
47
55
|
JSON.load("[#{response.body_str}]").first
|
48
56
|
end
|
49
57
|
|
50
|
-
def build_uri(contactually_method, args={})
|
51
|
-
|
52
|
-
"https://www.contactually.com/api/v1/#{contactually_method}.json?api_key=#{@api_key}"
|
58
|
+
def build_uri(contactually_method, args = {})
|
59
|
+
id_arg = args.has_key?(:id) ? "/#{args["id"]}" : ""
|
60
|
+
"https://www.contactually.com/api/v1/#{contactually_method}#{id_arg}.json?api_key=#{@api_key}"
|
53
61
|
end
|
54
62
|
|
55
|
-
def get_methods(
|
56
|
-
|
63
|
+
def get_methods(composite)
|
64
|
+
http_action, contactually_method = composite.to_s.split("_", 2)
|
65
|
+
return false unless HTTP_ACTIONS.include?(http_action)
|
66
|
+
return false unless METHODS.include?(contactually_method)
|
67
|
+
[@http_action = http_action, @contactually_method = contactually_method]
|
57
68
|
end
|
58
69
|
|
59
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contactually
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guille Carlos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Write a gem description
|
14
14
|
email:
|