Module: SmartlistPushApi

Defined in:
lib/smartlist_push_api.rb,
lib/smartlist_push_api/user.rb,
lib/smartlist_push_api/custom.rb,
lib/smartlist_push_api/version.rb,
lib/smartlist_push_api/http/http_client.rb

Defined Under Namespace

Modules: Http Classes: Custom, InvalidDataException, User

Constant Summary collapse

VERSION =
"0.1.14"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_tokenObject

Returns the value of attribute access_token.



14
15
16
# File 'lib/smartlist_push_api.rb', line 14

def access_token
  @access_token
end

.base_uriObject

Returns the value of attribute base_uri.



14
15
16
# File 'lib/smartlist_push_api.rb', line 14

def base_uri
  @base_uri
end

Class Method Details

.make_delete_request(url) ⇒ Object



29
30
31
# File 'lib/smartlist_push_api.rb', line 29

def self.make_delete_request(url)
  SmartlistPushApi.make_request(:GET, url)
end

.make_get_request(url) ⇒ Object



25
26
27
# File 'lib/smartlist_push_api.rb', line 25

def self.make_get_request(url)
  SmartlistPushApi.make_request(:GET, url)
end

.make_patch_request(url, data) ⇒ Object



21
22
23
# File 'lib/smartlist_push_api.rb', line 21

def self.make_patch_request(url, data)
  SmartlistPushApi.make_request(:PATCH, url, data)
end

.make_post_request(url, data) ⇒ Object



17
18
19
# File 'lib/smartlist_push_api.rb', line 17

def self.make_post_request(url, data)
  SmartlistPushApi.make_request(:POST, url, data)
end

.make_request(request_method, url, data = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/smartlist_push_api.rb', line 33

def self.make_request(request_method, url, data = nil)

  http_client = Http::HttpClient.new
  if request_method == :POST
    raise InvalidDataException if data.nil?

    response = http_client.post_request(url, data)
    return response.code == 200
  elsif request_method == :PATCH
    raise InvalidDataException if data.nil?

    response = http_client.patch_request(url, data)
    return response.code == 200
  elsif request_method == :GET
    response = http_client.get_request(url)
    return response.code == 200
  elsif request_method == :DELETE
    response = http_client.delete_request(url)
    return response.code == 204
  end

  return false
rescue => e
  return false
end