Class: ChimpRewriter

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/chimp_rewriter.rb,
lib/chimp_rewriter/version.rb

Defined Under Namespace

Classes: ChimpRewriterError

Constant Summary collapse

VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, app_id, api_key) ⇒ ChimpRewriter

Returns a new instance of ChimpRewriter.



13
14
15
16
17
# File 'lib/chimp_rewriter.rb', line 13

def initialize email, app_id, api_key
  @email = email
  @app_id = app_id
  @api_key = api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



11
12
13
# File 'lib/chimp_rewriter.rb', line 11

def api_key
  @api_key
end

#app_idObject (readonly)

Returns the value of attribute app_id.



11
12
13
# File 'lib/chimp_rewriter.rb', line 11

def app_id
  @app_id
end

#emailObject (readonly)

Returns the value of attribute email.



11
12
13
# File 'lib/chimp_rewriter.rb', line 11

def email
  @email
end

Instance Method Details

#authentication_paramsObject



19
20
21
# File 'lib/chimp_rewriter.rb', line 19

def authentication_params
  {email: email, aid: app_id, apikey: api_key}
end

#chimp_rewrite(text, options = {}) ⇒ Object



32
33
34
35
# File 'lib/chimp_rewriter.rb', line 32

def chimp_rewrite text, options = {}
  response_hash = make_request "ChimpRewrite", options.merge(text: text)
  response_hash["output"]
end

#create_spin(text, options = {}) ⇒ Object



37
38
39
40
# File 'lib/chimp_rewriter.rb', line 37

def create_spin text, options = {}
  response_hash = make_request "CreateSpin", options.merge(text: text)
  response_hash["output"]
end

#statisticsObject



23
24
25
26
27
28
29
30
# File 'lib/chimp_rewriter.rb', line 23

def statistics
  response_hash = make_request "Statistics"
  response_hash.delete "error"
  response_hash.each_pair do |key, value|
    response_hash[key] = value.to_i if value.to_i.to_s == value
  end
  OpenStruct.new response_hash
end