Class: MarketingAPI
- Inherits:
-
Object
- Object
- MarketingAPI
- Defined in:
- lib/marketing_api.rb
Instance Attribute Summary collapse
-
#port ⇒ Object
Returns the value of attribute port.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
- #create_optin(json_string) ⇒ Object
- #deactivate_optin(id) ⇒ Object
-
#get_optin(id) ⇒ Object
it is easy to go with get.
-
#initialize(server = "web.ict.kth.se/~chyrkov", port = 80) ⇒ MarketingAPI
constructor
A new instance of MarketingAPI.
- #update_optin(json_string) ⇒ Object
Constructor Details
#initialize(server = "web.ict.kth.se/~chyrkov", port = 80) ⇒ MarketingAPI
Returns a new instance of MarketingAPI.
8 9 10 11 |
# File 'lib/marketing_api.rb', line 8 def initialize(server="web.ict.kth.se/~chyrkov", port=80) @server = server @port = port end |
Instance Attribute Details
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/marketing_api.rb', line 6 def port @port end |
#server ⇒ Object
Returns the value of attribute server.
6 7 8 |
# File 'lib/marketing_api.rb', line 6 def server @server end |
Instance Method Details
#create_optin(json_string) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/marketing_api.rb', line 24 def create_optin(json_string) req = Net::HTTP::Post.new("/create", initheader = {'Content-Type' =>'application/json'}) req.body = json_string response = Net::HTTP.new(@server, @port).start {|http| http.request(req) } if response.code == "200" return true else return nil end end |
#deactivate_optin(id) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/marketing_api.rb', line 46 def deactivate_optin(id) req = Net::HTTP::Post.new("/deactivate/#{id}", initheader = {'Content-Type' =>'application/json'}) response = Net::HTTP.new(@server, @port).start {|http| http.request(req) } if response.code == "200" return true else return nil end end |
#get_optin(id) ⇒ Object
it is easy to go with get
14 15 16 17 18 19 20 21 22 |
# File 'lib/marketing_api.rb', line 14 def get_optin(id) uri = URI.parse("http://web.ict.kth.se/~chyrkov:80/#{id}") response = Net::HTTP.get_response(uri) if response.code == "200" return response.body else return nil end end |
#update_optin(json_string) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/marketing_api.rb', line 35 def update_optin(json_string) req = Net::HTTP::Post.new("/update", initheader = {'Content-Type' =>'application/json'}) req.body = json_string response = Net::HTTP.new(@server, @port).start {|http| http.request(req) } if response.code == "200" return true else return nil end end |