Class: Userfox::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/userfox/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret) ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/userfox/client.rb', line 8

def initialize(client_id, client_secret)
  @auth = { username: client_id, password: client_secret }
end

Instance Method Details

#change(from, to, options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/userfox/client.rb', line 29

def change(from, to, options = {})
  options[:body] = { from: from, to: to }

  post("/change.json", options)
end

#post(path, options = {}) ⇒ Object



12
13
14
15
# File 'lib/userfox/client.rb', line 12

def post(path, options = {})
  options.merge!({ basic_auth: @auth })
  handle_response { self.class.post(path, options) }
end

#send(email, name, delta = {}, options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/userfox/client.rb', line 23

def send(email, name, delta = {}, options = {})
  options[:body] = { addr: email, name: name, delta: delta.to_json }

  post("/send.json", options)
end

#track(email, url, delta = {}, options = {}) ⇒ Object



17
18
19
20
21
# File 'lib/userfox/client.rb', line 17

def track(email, url, delta = {}, options = {})
  options[:body] = { addr: email, url: url, delta: delta.to_json }

  post("/track.json", options)
end

#unsubscribes(email, options = {}) ⇒ Object



35
36
37
38
39
# File 'lib/userfox/client.rb', line 35

def unsubscribes(email, options = {})
  options[:body] = { addr: email }

  post("/unsubscribes.json", options)
end