cheetahmails 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -0
  3. data/lib/cheetahmails.rb +17 -27
  4. metadata +1 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ac87fd52f32e584182c5cf06c60c123e1ad3255
4
- data.tar.gz: be0f0e27b5b5fd6ea1041e7dfc84416b239a9f19
3
+ metadata.gz: d3ec8ac69916c77a941007e1fddc41708398bad7
4
+ data.tar.gz: 4306f5a649501c0177e142612d875c98d2b5fca8
5
5
  SHA512:
6
- metadata.gz: f98c72f1a28ac4144d7a00412e028fdbdc20ecfc24dcc3c14c6116ad17841197f2db76ab99235266d0238992ca8fe6edced3e22c5c4d5e430222db06922f5b80
7
- data.tar.gz: e45614047fbe3d415c98cf338c27782a42490078b915d487f0b9f6f9e748d945e5891263e089fd97f35390ffb92febd858aecc156a60d94c5f87bb8f04429aec
6
+ metadata.gz: b2fff01fb3c7628e643a7b4ecb7360ce02ea1ac9f1d8c9c181732f8a29759e6a953ba7fa26e86876f577b5e536285ec78c4ce76aad5b7120ee8d943e3e611df1
7
+ data.tar.gz: 8297b710d12becd0f287a9e8b93b34213898cbf48d2d5a2fb496f9ede92b83165594582742613c5bed40b760be375b1fde7957d8f59f8cd7f882dfafb908dc0a
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in surveymonkey.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'guard-rspec', '~> 4.3.1', require: false
8
+ gem 'rspec', require: false
9
+ gem 'dotenv', require: false
10
+ end
@@ -63,22 +63,19 @@ module Cheetahmails
63
63
  end
64
64
  end
65
65
 
66
- def self.find_list_member(email, prop='')
67
- tries ||= 2
68
-
66
+ def self.find_list_member(email, prop = '', allow_retry_qty = 3)
69
67
  faraday = Faraday.new(:url => @base_uri) do |faraday|
70
- faraday.request :url_encoded # form-encode POST params
71
- #faraday.response :logger # log requests to STDOUT
72
- faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
68
+ faraday.request :url_encoded
69
+ faraday.adapter Faraday.default_adapter
73
70
  end
74
71
 
75
- faraday.headers["Authorization"] = "Bearer " + self.get_token(tries < 2)
72
+ faraday.headers["Authorization"] = "Bearer #{Cheetahmails.get_token(false)}"
76
73
  faraday.headers["Content-Type"] = "application/json"
77
74
  faraday.headers["Accept"] = "application/json"
78
75
 
79
76
  params = {
80
77
  "viewName" => Cheetahmails.configuration.view_name,
81
- "prop" => prop, #first_name,last_name
78
+ "prop" => prop,
82
79
  "columnName" => "email_address",
83
80
  "operation" => "=",
84
81
  "param" => email
@@ -86,25 +83,18 @@ module Cheetahmails
86
83
 
87
84
  response = faraday.get '/services2/api/SearchRecords', params
88
85
 
89
- begin
90
- jsonresponse = JSON.parse(response.body)
91
- rescue JSON::ParserError => error
92
- raise response.statzus.to_s + " " + response.body
93
- end
94
-
95
- raise RetryException, jsonresponse["message"] if response.status == 401
96
-
97
- return false if response.status == 404
98
-
99
- begin
100
- return jsonresponse[0]
101
- rescue => error
102
- return false
103
- end
104
-
105
- rescue RetryException => e
106
- if (tries -= 1) > 0
107
- retry
86
+ case response.status
87
+ when 200
88
+ return JSON.parse(response.body)[0]
89
+ when 404
90
+ return false
91
+ when 401
92
+ if allow_retry_qty > 0
93
+ Cheetahmails.get_token(true)
94
+ find_list_member(email, prop, allow_retry_qty - 1)
95
+ else
96
+ raise "401"
97
+ end
108
98
  end
109
99
  end
110
100
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cheetahmails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Holder
@@ -38,34 +38,6 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 3.0.1
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: dotenv
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
41
  description: Some basic cheetah mail API end points implemented
70
42
  email: tom@simpleweb.co.uk
71
43
  executables: []