ikbis 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/LICENSE +20 -0
- data/README +9 -0
- data/README.markdown +97 -0
- data/Rakefile +43 -0
- data/VERSION.yml +4 -0
- data/bin/ikbis-auth +33 -0
- data/lib/ikbis.rb +14 -0
- data/lib/ikbis/advanced.rb +12 -0
- data/lib/ikbis/advanced/base.rb +89 -0
- data/lib/ikbis/advanced/media.rb +264 -0
- data/lib/ikbis/advanced/photo.rb +171 -0
- data/lib/ikbis/advanced/test.rb +50 -0
- data/lib/ikbis/advanced/upload.rb +164 -0
- data/lib/ikbis/advanced/video.rb +172 -0
- data/lib/ikbis/simple.rb +12 -0
- data/lib/ikbis/simple/base.rb +10 -0
- data/lib/ikbis/simple/channel.rb +21 -0
- data/lib/ikbis/simple/photo.rb +25 -0
- data/lib/ikbis/simple/user.rb +49 -0
- data/lib/ikbis/simple/video.rb +25 -0
- data/test/ikbis_test.rb +7 -0
- data/test/test_helper.rb +7 -0
- metadata +109 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
ZZCopyright (c) 2008 Moski Doski
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# Ikbis API GEM
|
2
|
+
This gem implements a full-featured ruby interface for the Ikbis API.
|
3
|
+
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
If you haven't already, add github's gem server to your sources:
|
7
|
+
|
8
|
+
gem sources -a http://gems.github.com
|
9
|
+
|
10
|
+
Then, it's as easy as:
|
11
|
+
|
12
|
+
sudo gem install ikbis
|
13
|
+
|
14
|
+
Add the gem plugin to your Rails project by adding the following to your @environment.rb@ file:
|
15
|
+
|
16
|
+
config.gem "ikbis", :lib => "ikbis"
|
17
|
+
|
18
|
+
|
19
|
+
## Use
|
20
|
+
There are two modules:
|
21
|
+
|
22
|
+
Ikbis::Simple
|
23
|
+
Ikbis::Advanced
|
24
|
+
|
25
|
+
## Simple API
|
26
|
+
|
27
|
+
The wrapper for the Simple API consists of the following classes and methods:
|
28
|
+
|
29
|
+
### Ikbis::Simple::User
|
30
|
+
|
31
|
+
Ikbis::Simple::User.info(username, response='xml')
|
32
|
+
|
33
|
+
|
34
|
+
# Advance API
|
35
|
+
The classes in Ikbis::Advanced must be instantiated. For example,
|
36
|
+
|
37
|
+
ikbis_video = Ikbis::Advanced::Video.new
|
38
|
+
ikbis_video.getInfo('moski_doski' , {:how => 'json'})
|
39
|
+
|
40
|
+
### Authentication
|
41
|
+
There are two steps you'll need to do to authenticate your application to Ikbis. First, you'll need to register your application with Ikbis. Log in to Ikbis as the user under whose account the messages should appear. Then go to http://ikbis.com/api/manage_keys. You will be asked to describe your application. Fill out the form and submit it. This will provide you with a client key and secret. Make note of them as you will need them for the next step.
|
42
|
+
|
43
|
+
Then, you'll need to do the OAuth exchange, which will give you an access token and secret. Open up a terminal and run:
|
44
|
+
|
45
|
+
ikbis-auth
|
46
|
+
|
47
|
+
This will prompt you for the client key and secret you just obtained. It will then echo a URL which you will need to visit while still logged in to Ikbis as the user from the previous step. You'll be asked to authorize your application. Click the Authorize button, then go back to your terminal and hit Return. The script will then get the access token and secret from Ikbis, and store all four pieces of information in a file called ikbis.yml. **Don't lose this file!** It constitutes the credentials that you will need to do anything useful with Ikbis. It is not encrypted, so keep it secure. Once you have the ikbis.yml file, you will not need to do these steps again unless you de-authorize the application.
|
48
|
+
|
49
|
+
|
50
|
+
Now to authenticate any call, you can do the following:
|
51
|
+
|
52
|
+
ikbis_video.oauth_authentication('path_to_ikbis.yml_file')
|
53
|
+
|
54
|
+
Any call you do with this object will use the your credentials when talking to ikbis.com
|
55
|
+
|
56
|
+
|
57
|
+
The wrapper for the Advanced API consists of the following classes and methods:
|
58
|
+
|
59
|
+
### Ikbis::Advanced::Test
|
60
|
+
|
61
|
+
echo(options={})
|
62
|
+
ping(options={})
|
63
|
+
login(options={})
|
64
|
+
|
65
|
+
### Ikbis::Advanced::Video
|
66
|
+
|
67
|
+
getUploadedList(username , {:how => 'json'})
|
68
|
+
getInfo(video_id , {:how => 'ruby'})
|
69
|
+
getThumbnailUrl(video_id , {:how => 'xml'})
|
70
|
+
setTitle(video_id , title , {:how => 'php'}) ## Must call oauth_authentication before use
|
71
|
+
setCaption(video_id , caption , {}) ## Must call oauth_authentication before use
|
72
|
+
|
73
|
+
|
74
|
+
### Ikbis::Advanced::Photo
|
75
|
+
|
76
|
+
getUploadedList(username , {:how => 'json'})
|
77
|
+
getInfo(video_id , {:how => 'ruby'})
|
78
|
+
getThumbnailUrl(video_id , {:how => 'xml'})
|
79
|
+
setTitle(video_id , title , {:how => 'php'}) ## Must call oauth_authentication before use
|
80
|
+
setCaption(video_id , caption , {}) ## Must call oauth_authentication before use
|
81
|
+
|
82
|
+
|
83
|
+
## Thanks to
|
84
|
+
|
85
|
+
* {Jeweler}[http://github.com/technicalpickles/jeweler/tree/master]: The best for gems.
|
86
|
+
* {HTTParty}[http://github.com/jnunemaker/httparty/tree/master].
|
87
|
+
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
Copyright (C) 2008 Ikbis (http://www.ikbis.com/)
|
92
|
+
|
93
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
94
|
+
|
95
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
96
|
+
|
97
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rcov/rcovtask'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |s|
|
9
|
+
s.name = "ikbis"
|
10
|
+
s.summary = "This gem implements a full-featured ruby interface for the Ikbis API."
|
11
|
+
s.email = "abushaikh@gmail.com"
|
12
|
+
s.homepage = "http://github.com/moski/ikbis"
|
13
|
+
s.description = "This gem implements a full-featured ruby interface for the Ikbis API."
|
14
|
+
s.authors = ["Moski Doski"]
|
15
|
+
s.add_dependency('multipart-post', '>= 1.0')
|
16
|
+
s.add_dependency('httparty', '>= 0.5.0')
|
17
|
+
s.add_dependency('oauth', '>= 0.3.6')
|
18
|
+
end
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
21
|
+
end
|
22
|
+
|
23
|
+
Rake::TestTask.new do |t|
|
24
|
+
t.libs << 'lib'
|
25
|
+
t.pattern = 'test/**/*_test.rb'
|
26
|
+
t.verbose = false
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::RDocTask.new do |rdoc|
|
30
|
+
rdoc.rdoc_dir = 'rdoc'
|
31
|
+
rdoc.title = 'ikbis'
|
32
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
33
|
+
rdoc.rdoc_files.include('README*')
|
34
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
35
|
+
end
|
36
|
+
|
37
|
+
Rcov::RcovTask.new do |t|
|
38
|
+
t.libs << 'test'
|
39
|
+
t.test_files = FileList['test/**/*_test.rb']
|
40
|
+
t.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :rcov
|
data/VERSION.yml
ADDED
data/bin/ikbis-auth
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'oauth/consumer'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
puts "Please enter your client key, then hit Return."
|
8
|
+
consumer_key = gets.chomp
|
9
|
+
puts "Please enter your client secret, then hit Return."
|
10
|
+
consumer_secret = gets.chomp
|
11
|
+
|
12
|
+
begin
|
13
|
+
consumer = OAuth::Consumer.new consumer_key, consumer_secret, { :site => "http://ikbis.com" }
|
14
|
+
request_token = consumer.get_request_token
|
15
|
+
puts "Please go to:\n#{request_token.authorize_url}\nin your browser. Click Authorize on that page.\nHit Return here when you are done."
|
16
|
+
gets
|
17
|
+
access_token = request_token.get_access_token
|
18
|
+
credentials = {
|
19
|
+
:consumer_key => consumer.key,
|
20
|
+
:consumer_secret => consumer.secret,
|
21
|
+
:access_token => access_token.token,
|
22
|
+
:access_token_secret => access_token.secret
|
23
|
+
}
|
24
|
+
begin
|
25
|
+
File.open('ikbis.yml', 'w') { |file| YAML.dump(credentials, file) }
|
26
|
+
File.chmod(0600, 'ikbis.yml')
|
27
|
+
puts "Your credentials have been saved."
|
28
|
+
rescue
|
29
|
+
puts "Couldn't save your credentials."
|
30
|
+
end
|
31
|
+
rescue
|
32
|
+
puts "Couldn't authorize with Ikbis. Did you enter your client credentials correctly?"
|
33
|
+
end
|
data/lib/ikbis.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require 'cgi'
|
4
|
+
require 'net/http'
|
5
|
+
require 'net/http/post/multipart'
|
6
|
+
require 'oauth/consumer'
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
$:.unshift(File.dirname(__FILE__))
|
10
|
+
require 'ikbis/simple'
|
11
|
+
require 'ikbis/advanced'
|
12
|
+
|
13
|
+
module Ikbis
|
14
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Ikbis
|
2
|
+
module Advanced
|
3
|
+
class Base
|
4
|
+
include HTTParty
|
5
|
+
base_uri 'ikbis.com'
|
6
|
+
#base_uri 'localhost:3000'
|
7
|
+
|
8
|
+
class CouldNotLoadCredentials < Exception; end
|
9
|
+
class CouldNotPost < Exception; end
|
10
|
+
|
11
|
+
attr_reader :access_token
|
12
|
+
|
13
|
+
#######################################################
|
14
|
+
# Authenticate using OAuth::Consumer.
|
15
|
+
# After calling this method, the user will be logged in
|
16
|
+
# in to ikbis and can use all the private methods.
|
17
|
+
#
|
18
|
+
# Prerequisites:
|
19
|
+
# Must call ikbis-auth to generate the credentials yaml file.
|
20
|
+
#
|
21
|
+
######################
|
22
|
+
# @Created : DEC/31/2007
|
23
|
+
# @LastRefactor : DEC/31/2007
|
24
|
+
# @Author : Monther Abushaikh <abushaikh@gmail.com>
|
25
|
+
#######################################################
|
26
|
+
def oauth_authentication(credential_file='credentials.yml')
|
27
|
+
begin
|
28
|
+
@credentials = YAML.load_file(credential_file)
|
29
|
+
rescue
|
30
|
+
raise CouldNotLoadCredentials, "Couldn't load your ikbis credentials. You may need to run ikbis-auth."
|
31
|
+
end
|
32
|
+
@consumer = OAuth::Consumer.new(@credentials[:consumer_key], @credentials[:consumer_secret], {:site => "http://localhost:3000"})
|
33
|
+
@access_token = OAuth::AccessToken.new(@consumer, @credentials[:access_token], @credentials[:access_token_secret])
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
#######################################################
|
39
|
+
# Send the request to ikbis and return the results.
|
40
|
+
# If @access_token is defined use OAuth::Consumer else use
|
41
|
+
# HTTParty to send request.
|
42
|
+
#
|
43
|
+
# Params:
|
44
|
+
# :method =>
|
45
|
+
# enum(get | post | put | delete)
|
46
|
+
# :id =>
|
47
|
+
# id of the resource we're manipulating
|
48
|
+
# :what =>
|
49
|
+
# method to perform, if empty, action taken will be controlled by the provided method,
|
50
|
+
# ie :method => get and :what => "" will retrieve the resource's info
|
51
|
+
# :method => post and :what => "" will create a resource
|
52
|
+
# :method => put and :what => "add_tag" will add a tag to resource with :id
|
53
|
+
# :how =>
|
54
|
+
# defines type of response; enum(xml | json | rb | php)
|
55
|
+
#
|
56
|
+
# Return:
|
57
|
+
# See :how in Params.
|
58
|
+
######################
|
59
|
+
# @Created : DEC/31/2007
|
60
|
+
# @LastRefactor : Jan/13/2010
|
61
|
+
# by: ahmad@ikbis
|
62
|
+
# @Author : Monther Abushaikh <abushaikh@gmail.com>
|
63
|
+
#######################################################
|
64
|
+
def send_request(options)
|
65
|
+
|
66
|
+
# construct our RESTful request URI
|
67
|
+
uri = "#{Base.base_uri}/api/#{options[:target]}"
|
68
|
+
uri += "/#{options[:id]}" if options.has_key?(:id)
|
69
|
+
uri += "/#{options[:what]}" if options.has_key?(:what)
|
70
|
+
uri += ".#{options[:how]}" if options[:method] == "get"
|
71
|
+
puts "|--------------------- SEND_REQUEST ---------------------|"
|
72
|
+
puts "| URI"
|
73
|
+
puts "| #{uri}"
|
74
|
+
puts "| Params"
|
75
|
+
puts "| id => #{options[:id]}"
|
76
|
+
puts "| what => #{options[:what]}"
|
77
|
+
puts "| how => #{options[:how]}"
|
78
|
+
puts "|--------------------- ------------ ---------------------|"
|
79
|
+
|
80
|
+
if @access_token.nil?
|
81
|
+
return self.class.send(options[:method] || "get", uri, options)
|
82
|
+
else
|
83
|
+
return @access_token.send(options[:method] || "get", uri, options).body
|
84
|
+
end
|
85
|
+
|
86
|
+
end ## end send_request
|
87
|
+
end ## end Base
|
88
|
+
end ## end Advanced
|
89
|
+
end ## end ikbis
|
@@ -0,0 +1,264 @@
|
|
1
|
+
module Ikbis
|
2
|
+
module Advanced
|
3
|
+
class Media < Ikbis::Advanced::Base
|
4
|
+
|
5
|
+
#######################################################
|
6
|
+
# Class constants:
|
7
|
+
# I. MEDIA_EXTENTION: used to override the methods names.
|
8
|
+
# II. RESERVER: List of reserved methods we don't need to
|
9
|
+
# override.
|
10
|
+
#######################################################
|
11
|
+
MEDIA_EXTENTION = 'media_'
|
12
|
+
RESERVED = ['initialize' , 'method_missing' , 'method_added']
|
13
|
+
|
14
|
+
#######################################################
|
15
|
+
# Try to generate the method name if its a valid method
|
16
|
+
# name and call the paret class.
|
17
|
+
######################
|
18
|
+
# @Created : Jan/19/2009
|
19
|
+
# @LastRefactor : Jan/19/2009
|
20
|
+
# @Author : Moski
|
21
|
+
#######################################################
|
22
|
+
def method_missing(key, *args, &block)
|
23
|
+
if @@valid_methods.include?(key.to_s)
|
24
|
+
(class << self; self; end).class_eval do
|
25
|
+
define_method(key) do |*args|
|
26
|
+
args.insert(0,"#{@class_extention}.#{key}")
|
27
|
+
send "#{MEDIA_EXTENTION}#{key}" , *args
|
28
|
+
end
|
29
|
+
end
|
30
|
+
send "#{key}" , *args
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end ## end method_missing
|
35
|
+
|
36
|
+
|
37
|
+
#######################################################
|
38
|
+
# When a method is defined added to the valid_methods
|
39
|
+
# array.
|
40
|
+
# This is just overriding the ruby hook method(method_added)
|
41
|
+
######################
|
42
|
+
# @Created : Jan/19/2009
|
43
|
+
# @LastRefactor : Jan/19/2009
|
44
|
+
# @Author : Moski
|
45
|
+
#######################################################
|
46
|
+
def self.method_added(name)
|
47
|
+
@@valid_methods ||= []
|
48
|
+
@@valid_methods << name.to_s.gsub(MEDIA_EXTENTION , '')
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
|
55
|
+
#######################################################
|
56
|
+
# Returns a sheet of all videos uploaded by user.
|
57
|
+
#
|
58
|
+
# NOTE:
|
59
|
+
# Now requires user_id instead of username.
|
60
|
+
#######################################################
|
61
|
+
# @ LastRefactor: Jan/06/2010
|
62
|
+
# @ Devs:
|
63
|
+
# Moski
|
64
|
+
# Ahmad
|
65
|
+
#######################################################
|
66
|
+
def getUploadedList(action_name , user_id, options = {})
|
67
|
+
setup_what_how("videos" , options)
|
68
|
+
|
69
|
+
# does not deal with medias controller, but with users instead...
|
70
|
+
options.merge!(:target => "users")
|
71
|
+
options.merge!(:id => user_id)
|
72
|
+
options.merge!(:method => "get")
|
73
|
+
|
74
|
+
return send_request(options)
|
75
|
+
end ## end function.
|
76
|
+
|
77
|
+
|
78
|
+
#######################################################
|
79
|
+
# Returns sheet of media info in specified format.
|
80
|
+
#######################################################
|
81
|
+
# @ LastRefactor: Jan/06/2010
|
82
|
+
# @ Devs:
|
83
|
+
# Moski
|
84
|
+
# Ahmad
|
85
|
+
#######################################################
|
86
|
+
def getInfo(action_name ,media_id , options = {})
|
87
|
+
# debug
|
88
|
+
puts "------ getInfo routine ------"
|
89
|
+
puts "* action_name => #{action_name}"
|
90
|
+
puts "* options => #{options}"
|
91
|
+
puts "--------------------------------"
|
92
|
+
|
93
|
+
# action name is empty here because info is the default
|
94
|
+
# GET response
|
95
|
+
setup_what_how("" , options)
|
96
|
+
options.merge!(:id => media_id)
|
97
|
+
options.merge!(:method => "get")
|
98
|
+
|
99
|
+
return send_request(options)
|
100
|
+
end ## end function
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
#######################################################
|
105
|
+
# Returns URL pointing to the thumbnail picture requested
|
106
|
+
# by size.
|
107
|
+
#
|
108
|
+
# params:
|
109
|
+
# * int media_id
|
110
|
+
# * string enum :size option
|
111
|
+
# {
|
112
|
+
# - medium_crop
|
113
|
+
# - screen
|
114
|
+
# - big_screen
|
115
|
+
# - medium
|
116
|
+
# - small
|
117
|
+
# - large
|
118
|
+
# - thumb
|
119
|
+
# }
|
120
|
+
#
|
121
|
+
# ex media.getThumbnailUrl("204732", :size => "large")
|
122
|
+
#######################################################
|
123
|
+
# @ LastRefactor: Jan/06/2010
|
124
|
+
# @ Devs:
|
125
|
+
# Moski
|
126
|
+
# Ahmad
|
127
|
+
#######################################################
|
128
|
+
def getThumbnailUrl(action_name , media_id , options = {})
|
129
|
+
|
130
|
+
# get vid info where thumb URIs are contained
|
131
|
+
media = getInfo(media_id)
|
132
|
+
|
133
|
+
# enforce a default value if none is provided
|
134
|
+
size = (options[:size].empty?) ? "thumb" : options[:size]
|
135
|
+
|
136
|
+
type = (media.type == "Image") ? "photo" : "video"
|
137
|
+
|
138
|
+
# since HTTParty parses the XML into a ruby hash,
|
139
|
+
# we only need to access the element and get our URI!
|
140
|
+
thumb_uri = media['ikbis'][type]['thumbnails'][size]
|
141
|
+
|
142
|
+
return thumb_uri
|
143
|
+
end ## end function
|
144
|
+
|
145
|
+
|
146
|
+
#######################################################
|
147
|
+
# Modifies title of specified media that belongs to the logged
|
148
|
+
# in user.
|
149
|
+
#######################################################
|
150
|
+
# @ LastRefactor: Jan/06/2010
|
151
|
+
# @ Devs:
|
152
|
+
# Moski
|
153
|
+
# Ahmad
|
154
|
+
#######################################################
|
155
|
+
def setTitle(action_name , media_id , title ,options = {})
|
156
|
+
# using PUT method allows us to update without
|
157
|
+
# specifying an action name, since it's a RESTful route
|
158
|
+
setup_what_how("" , options)
|
159
|
+
options.merge!(:method => "put")
|
160
|
+
options.merge!(:id => media_id)
|
161
|
+
options.merge!(:title => CGI.escape(title))
|
162
|
+
|
163
|
+
return send_request(options)
|
164
|
+
end
|
165
|
+
|
166
|
+
#######################################################
|
167
|
+
# Modifies caption of specified media that belongs to the
|
168
|
+
# logged in user.
|
169
|
+
#######################################################
|
170
|
+
# @ LastRefactor: Jan/06/2010
|
171
|
+
# @ Devs:
|
172
|
+
# Moski
|
173
|
+
# Ahmad
|
174
|
+
#######################################################
|
175
|
+
def setCaption(action_name,media_id , caption ,options = {})
|
176
|
+
setup_what_how("", options)
|
177
|
+
options.merge!(:id => media_id)
|
178
|
+
options.merge!(:caption => CGI.escape(caption))
|
179
|
+
options.merge!(:method => "put")
|
180
|
+
|
181
|
+
return send_request(options)
|
182
|
+
end
|
183
|
+
|
184
|
+
# DEPRECATED
|
185
|
+
#def setFavorite(action_name, media_id , favorite = 'yes' ,options = {})
|
186
|
+
# setup_what_how(action_name , options)
|
187
|
+
# options.merge!(:media_id => media_id)
|
188
|
+
# options.merge!(:favorite => favorite)
|
189
|
+
# return send_request(options)
|
190
|
+
#end
|
191
|
+
|
192
|
+
#######################################################
|
193
|
+
# Adds 1 tag at a time to media.
|
194
|
+
# NOTE:
|
195
|
+
# trying to add more than one tag using a ' ' space delimiter
|
196
|
+
# will result in an escaped '+' character instead.
|
197
|
+
#######################################################
|
198
|
+
# @ LastRefactor: Jan/06/2010
|
199
|
+
# @ Devs:
|
200
|
+
# Moski
|
201
|
+
# Ahmad
|
202
|
+
#######################################################
|
203
|
+
def addTag(action_name, media_id , tags ,options = {})
|
204
|
+
setup_what_how("add_tag", options)
|
205
|
+
options.merge!(:id => media_id)
|
206
|
+
options.merge!(:tag => CGI.escape(tags))
|
207
|
+
options.merge!(:method => "put")
|
208
|
+
|
209
|
+
return send_request(options)
|
210
|
+
end
|
211
|
+
|
212
|
+
#######################################################
|
213
|
+
# Removes all occurences of 'tag' in media's tags.
|
214
|
+
#######################################################
|
215
|
+
# @ LastRefactor: Jan/06/2010
|
216
|
+
# @ Devs:
|
217
|
+
# Moski
|
218
|
+
# Ahmad
|
219
|
+
#######################################################
|
220
|
+
def removeTag(action_name, media_id , tag ,options = {})
|
221
|
+
setup_what_how("remove_tag" , options)
|
222
|
+
options.merge!(:id => media_id)
|
223
|
+
options.merge!(:tag => CGI.escape(tag))
|
224
|
+
options.merge!(:method => "put")
|
225
|
+
|
226
|
+
return send_request(options)
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
#######################################################
|
231
|
+
# Rename the Class methods by added the media extention to
|
232
|
+
# it and remove the old definition.
|
233
|
+
######################
|
234
|
+
# @Created : Jan/19/2009
|
235
|
+
# @LastRefactor : Jan/19/2009
|
236
|
+
# @Author : Moski
|
237
|
+
#######################################################
|
238
|
+
class_eval{instance_methods(false).each {|m|
|
239
|
+
unless RESERVED.include?(m)
|
240
|
+
alias_method "#{MEDIA_EXTENTION}#{m}" , m ;undef_method m
|
241
|
+
end
|
242
|
+
}}
|
243
|
+
|
244
|
+
|
245
|
+
private
|
246
|
+
|
247
|
+
#######################################################
|
248
|
+
# Just a common helper method to add the action_name and the
|
249
|
+
# return type.
|
250
|
+
######################
|
251
|
+
# @Created : Jan/19/2009
|
252
|
+
# @LastRefactor : Jan/19/2009
|
253
|
+
# @Author : Moski
|
254
|
+
#######################################################
|
255
|
+
def setup_what_how(action_name , options)
|
256
|
+
options.merge!(:target => "medias")
|
257
|
+
options.merge!(:what => action_name)
|
258
|
+
options.merge!(:how => 'xml') unless options.has_key?(:how)
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
end ## end class
|
263
|
+
end## end advanced
|
264
|
+
end ## end ikbis
|