contactually 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2744934fe9ac93c12fb2ce2919ab4c25a15cecf7
4
- data.tar.gz: 1211d34bee6b7e0bfd342c83138d7e5c5a5da233
3
+ metadata.gz: 48c659debeddaa05a2693dfed4014feaf8cb600d
4
+ data.tar.gz: 435cae2af1c168709ead2ded43c98f50deffb1a1
5
5
  SHA512:
6
- metadata.gz: a8ce41005b490e177675b8789f64e3f7c0a6678d0b86614f635871d34b28f84ed90824d83c26c23cb6c4eed207f15bd57ce9127f214be61948670fa9c2a29d13
7
- data.tar.gz: fcf8965833261d1e223737a4da533d76b8190fef3822a937865ccb3bc1160fcdab9c0c05252429d0dc7bc1d7ea19babcf30d2afaf3471319482fe2346fe53774
6
+ metadata.gz: 1850c19b622ed5b3ad346883de6486db01be17efb76d40766ced7e1a5d32a1927b7e7150c7c1fd5bb673c9378a12fcb32427398ca91a201414055b0d49badca0
7
+ data.tar.gz: 87a78219cba198cf9afc4431cf12e289df50f24b056bdb2b3c6858d670ef97ea3995929179394d0e02e3ed7798671fcecf7f7fb91c20c6daed5d047e72be40d8
@@ -1,3 +1,3 @@
1
1
  module Contactually
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/contactually.rb CHANGED
@@ -4,6 +4,8 @@ require "json"
4
4
  module Contactually
5
5
  class API
6
6
 
7
+ ReturnValue = Struct.new(:code, :body)
8
+
7
9
  HTTP_ACTIONS = %w(get post put delete).freeze
8
10
  METHODS = %w(contacts notes groupings).freeze
9
11
 
@@ -43,7 +45,9 @@ module Contactually
43
45
  end
44
46
 
45
47
  def make_call(composite, params = {})
46
- return false unless get_methods(composite)
48
+ unless get_methods(composite)
49
+ return ReturnValue.new(400, "Bad action/method '#{composite}'")
50
+ end
47
51
  uri = build_uri(contactually_method, params)
48
52
  response = Curl.send(http_action.to_sym, uri, param_fields(params)) do |curl|
49
53
  @headers.each do |header_name, header_value|
@@ -52,7 +56,16 @@ module Contactually
52
56
  curl.headers['Accept'] = 'application/json'
53
57
  curl.headers['Content-Type'] = 'application/json'
54
58
  end
55
- JSON.load("[#{response.body_str}]").first
59
+
60
+ if [200, 201, 202].include?(response.response_code)
61
+ return ReturnValue.new(
62
+ response.response_code,
63
+ JSON.load("[#{response.body_str}]").first
64
+ )
65
+ end
66
+ ReturnValue.new(response.response_code, response.body_str)
67
+ rescue => e
68
+ ReturnValue.new(500, "Could not complete call, #{e.message}")
56
69
  end
57
70
 
58
71
  def build_uri(contactually_method, args = {})
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.3
4
+ version: 0.0.4
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-23 00:00:00.000000000 Z
11
+ date: 2015-03-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Write a gem description
14
14
  email: