Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added support for deleting live pics

  • Loading branch information...
commit a1df777d815cde0120255598d67f49f40132b8f0 1 parent 5153f1e
@briandoll authored
View
4 README.md
@@ -40,7 +40,11 @@ Include the Module:
# => #<LivePic id=123, ...>
MovableInkClient.update_live_pic
+ # => #<LivePic id=123, ...>
+ lp = MovableInkClient.live_pics.first
+ MovableInkClient.delete_live_pic lp
+ # => true
**Creative Optimizers**
View
17 lib/movableink-api/api.rb
@@ -84,6 +84,15 @@ def self.put(api_path, params = nil)
process_response response
end
+ def self.delete(api_path)
+ url = build_url(api_path)
+ http = Net::HTTP.new(url.host)
+ request = Net::HTTP::Delete.new("#{url.path}?#{url.query}")
+ response = http.request(request)
+ response.kind_of?(Net::HTTPOK)
+ end
+
+
# Build a URI object reprsenting an API URL based on the parameters provided
#
# api_path - The API method to invoke
@@ -95,7 +104,7 @@ def self.put(api_path, params = nil)
# # => #<URI::HTTP:0x101afe1a8 URL:http://movableink.com/api/v1/live_pics?token=xxxxx>
#
# Returns a URI object representing the URL for an API call
- # Returns ArgumentError if the MovableInk::API.token is empty
+ # Returns ArgumentError if the MovableInkClient.token is empty
def self.build_url(api_path, params = nil)
validate_request
url = URI.parse(NAMESPACE + api_path)
@@ -107,12 +116,12 @@ def self.build_url(api_path, params = nil)
# Validate that all required parameters are set for a given API call
#
- # Currently only checks to see that the MovableInk::API.token is set
+ # Currently only checks to see that the MovableInkClient.token is set
#
# Returns nothing.
- # Raises ArgumentError if the MovableInk::API.token is empty
+ # Raises ArgumentError if the MovableInkClient.token is empty
def self.validate_request
- raise ArgumentError.new "Please set your MovableInk API token before any calls to the API. ex. MovableInk::API.token(yourtoken)" if token.nil?
+ raise ArgumentError.new "Please set your MovableInk API token before any calls to the API. ex. MovableInkClient.token(yourtoken)" if token.nil?
end
# Convert response body to JSON if the response is not an error
View
39 lib/movableink-api/real-time.rb
@@ -7,11 +7,11 @@ module RealTime
#
# Examples
#
- # MovableInk::API.live_pics
+ # MovableInkClient.live_pics
# # => [#<LivePic collection_id=nil, ...>, ...]
#
# Returns an array of LivePic instances
- # Returns ArgumentError if MovableInk::API.token is empty
+ # Returns ArgumentError if MovableInkClient.token is empty
def live_pics(offset = nil, limit = nil)
pics = LivePics.new(get("live_pics", {:offset => offset, :limit => limit}))
pics.live_pics
@@ -24,11 +24,11 @@ def live_pics(offset = nil, limit = nil)
#
# Examples
#
- # MovableInk::API.live_pic '123'
+ # MovableInkClient.live_pic '123'
# # => #<LivePic id=123, ...>
#
# Returns a LivePic instance
- # Returns ArgumentError if MovableInk::API.token is empty
+ # Returns ArgumentError if MovableInkClient.token is empty
def live_pic(live_pic_id)
response = get("live_pics/#{live_pic_id}")
LivePic.new response["live_pic"]
@@ -40,11 +40,11 @@ def live_pic(live_pic_id)
#
# Examples
#
- # MovableInk::API.live_pic_stats '123'
+ # MovableInkClient.live_pic_stats '123'
# # => #<LivePicStats id=123, ...>
#
# Returns a LivePicStats instance
- # Returns ArgumentError if MovableInk::API.token is empty
+ # Returns ArgumentError if MovableInkClient.token is empty
def live_pic_stats(live_pic_id)
response = get("live_pics/#{live_pic_id}/stats")
LivePicStats.new response["live_pic"]["stats"]
@@ -57,11 +57,11 @@ def live_pic_stats(live_pic_id)
# Examples
#
# lp = LivePic.new(:name => "my name", ...)
- # MovableInk::API.create_live_pic lp
+ # MovableInkClient.create_live_pic lp
# # => #<LivePic name='my name', id='123' ...>
#
# Returns a LivePic instance that represents the newly created live pic
- # Returns ArgumentError if MovableInk::API.token is empty
+ # Returns ArgumentError if MovableInkClient.token is empty
def create_live_pic(live_pic)
params = live_pic.to_params
response = post("live_pics", params)
@@ -74,17 +74,34 @@ def create_live_pic(live_pic)
#
# Examples
#
- # lp = MovableInk::API.live_pics[0]
+ # lp = MovableInkClient.live_pics.first
# lp.name = "Updated Name"
- # MovableInk::API.update_live_pic(lp)
+ # MovableInkClient.update_live_pic(lp)
# # => #<LivePic name='Updated Name', id='123' ...>
#
# Returns a LivePic instance that represents the newly udpated live pic
- # Returns ArgumentError if MovableInk::API.token is empty
+ # Returns ArgumentError if MovableInkClient.token is empty
def update_live_pic(live_pic)
params = live_pic.to_params
response = put("live_pics/#{live_pic.id}", params)
LivePic.new response["live_pic"]
end
+ # Public: Delete a live pic
+ #
+ # live_pic - The live pic to delete
+ #
+ # Examples
+ #
+ # lp = MovableInkClient.live_pic.first
+ # MovableInkClient.delete_live_pic(lp)
+ # # => true
+ #
+ # Returns true if the live pic was deleted, otherwise false
+ # Returns ArgumentError if MovableInkClient.token is empty
+ def delete_live_pic(live_pic)
+ response = delete("live_pics/#{live_pic.id}")
+
+ end
+
end
View
9 test/test_real_time.rb
@@ -65,7 +65,7 @@ def test_create_live_pic
def test_update_live_pic
MovableInkClient.token = ::API_KEY
- lp = MovableInkClient.live_pics[0]
+ lp = MovableInkClient.live_pics.first
updated_pic_id = lp.id
name = "Updated Name - #{Time.now.to_i}"
lp.name = name
@@ -74,4 +74,11 @@ def test_update_live_pic
assert updated_pic.name, name
end
+ def test_delete_live_pic
+ MovableInkClient.token = ::API_KEY
+ lp = MovableInkClient.live_pics.first
+ deleted = MovableInkClient.delete_live_pic lp
+ assert deleted
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.