ikbis 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,171 @@
1
+ module Ikbis
2
+ module Advanced
3
+ class Photo < Ikbis::Advanced::Media
4
+ #######################################################
5
+ # Set the class extention string for this class.
6
+ ######################
7
+ # @Created : Jan/19/2009
8
+ # @LastRefactor : Jan/19/2009
9
+ # @Author : Monther Abushaikh <abushaikh@gmail.com>
10
+ #######################################################
11
+ def initialize
12
+ @class_extention = "ikbis.photos"
13
+ super ### call the media initialize function.
14
+ end
15
+
16
+
17
+ #######################################################
18
+ # getUploadedList
19
+ # -> This gets a list of photos uploaded by the specified user.
20
+ # -> If the calling user is logged in, this will return information that calling
21
+ # -> user has access to (including private photos). If the calling user is not authenticated,
22
+ # -> this will only return public information, or a permission denied error if none is available.
23
+ #
24
+ # Parameters
25
+ # * string username- ex.(moski_doski)
26
+ # * options:
27
+ # * int page - Which page to show.
28
+ # * int per_page - How many results per page?
29
+ # * string how - xml or json or php
30
+ #
31
+ # ex: getUploadedList('moski_doski' , {:how => 'json'})
32
+ #
33
+ # Returns:
34
+ # -> <photos>
35
+ # <photo>
36
+ # <id>142139</id>
37
+ # <title>In the office</title>
38
+ # <caption>In the office</caption>
39
+ # <views>61</views>\n
40
+ # <category></category>\n
41
+ # <owner>moski_doski</owner>\n
42
+ # <comments>0</comments>\n
43
+ # <rating>0</rating>\n
44
+ # <thumbnails>\n
45
+ # <small>http://shots.ikbis.com/image/142139/small/Photo_107.jpg</small>\n
46
+ # <thumb>http://shots.ikbis.com/image/142139/thumb/Photo_107.jpg</thumb>\n
47
+ # <medium_crop>http://shots.ikbis.com/image/142139/medium_crop/Photo_107.jpg</medium_crop>\n
48
+ # <medium>http://shots.ikbis.com/image/142139/medium/Photo_107.jpg</medium>\n
49
+ # <screen>http://shots.ikbis.com/image/142139/screen/Photo_107.jpg</screen>\n
50
+ # <big_screen>http://shots.ikbis.com/image/142139/big_screen/Photo_107.jpg</big_screen>\n
51
+ # <large>http://shots.ikbis.com/image/142139/large/Photo_107.jpg</large>\n
52
+ # </thumbnails>\n
53
+ # </photo>
54
+ # </photos>
55
+ #
56
+ # Authentication
57
+ # -> Authentication is not required.
58
+ ######################
59
+ # @Created : DEC/31/2008
60
+ # @LastRefactor : DEC/31/2008
61
+ # @Author : Moski
62
+ #######################################################
63
+ ### Auto-generated using method_missing ####
64
+
65
+
66
+ #######################################################
67
+ # getInfo
68
+ # -> Get all kinds of information about a photo
69
+ # -> If the calling user is logged in, this will return information
70
+ # -> that calling user has access to (including private photos).
71
+ # -> If the calling user is not authenticated, this will only return
72
+ # public information, or a permission denied error if none is available.
73
+ # Parameters
74
+ # * int media_id (required) - Get information from this id
75
+ #
76
+ # ex: getInfo('103678' , {:how => 'json'})
77
+ #
78
+ # Returns:
79
+ # -> <photo>\n <id>103678</id>\n <title>First Album</title>\n <caption>Cool avatars</caption>\n <views>171</views>\n
80
+ # <category></category>\n <owner>moski_doski</owner>\n <comments>0</comments>\n <rating>0</rating>\n <thumbnails>\n
81
+ # <small>http://shots.ikbis.com/image/103678/small/Another_ID_by_pyromaniac.png</small>\n
82
+ # <thumb>http://shots.ikbis.com/image/103678/thumb/Another_ID_by_pyromaniac.png</thumb>\n
83
+ # <medium_crop>http://shots.ikbis.com/image/103678/medium_crop/Another_ID_by_pyromaniac.png</medium_crop>\n
84
+ # <medium>http://shots.ikbis.com/image/103678/medium/Another_ID_by_pyromaniac.png</medium>\n
85
+ # <screen>http://shots.ikbis.com/image/103678/screen/Another_ID_by_pyromaniac.png</screen>\n
86
+ # <big_screen>http://shots.ikbis.com/image/103678/big_screen/Another_ID_by_pyromaniac.png</big_screen>\n
87
+ # <large>http://shots.ikbis.com/image/103678/large/Another_ID_by_pyromaniac.png</large>\n </thumbnails>\n</photo>
88
+ #
89
+ # Authentication
90
+ # -> Authentication is not required.
91
+ ######################
92
+ # @Created : DEC/31/2008
93
+ # @LastRefactor : DEC/31/2008
94
+ # @Author : Moski
95
+ #######################################################
96
+ ### Auto-generated using method_missing ####
97
+
98
+
99
+ #######################################################
100
+ # getThumbnailUrl
101
+ # -> Get a thumbnail URL for a given photo/size
102
+ #
103
+ # Parameters
104
+ # * int media_id (required) - Get information from this video
105
+ # * thumbnail_size:
106
+ # small "70x70" and crop => "1:1"
107
+ # thumb "90x90" and crop => "1:1"
108
+ # medium_crop "144x144" and crop => "1:1"
109
+ # medium "240x240" and no crop
110
+ # screen "420x420" and no crop
111
+ # big_screen "500x500" and no crop
112
+ # large "800x800" and no crop
113
+ # all return all sizes
114
+ # Returns:
115
+ # -> <thumbnails>
116
+ # <small>http://shots.ikbis.com/video_thumbnail/110774/small/video.jpg</small>\n
117
+ # <thumb>http://shots.ikbis.com/video_thumbnail/110774/thumb/video.jpg</thumb>\n
118
+ # <medium_crop>http://shots.ikbis.com/video_thumbnail/110774/medium_crop/video.jpg</medium_crop>
119
+ # ..........
120
+ # </thumbnails>
121
+ # Authentication
122
+ # -> Authentication is not required.
123
+ ######################
124
+ # @Created : DEC/31/2008
125
+ # @LastRefactor : DEC/31/2008
126
+ # @Author : Moski
127
+ ######################################################
128
+ ### Auto-generated using method_missing ####
129
+
130
+
131
+ #######################################################
132
+ # setTitle
133
+ # -> Set the title of a photo (overwrites previous title)
134
+ # Parameters
135
+ # * int media_id (required) - Set the title of this photo.
136
+ # * string title (required) - The new title. 128 is the max length for this field, any longer and it will be trimmed.
137
+ #
138
+ # ex: setTitle(media_id , "My cool new title" ,{:how => 'json'})
139
+ #
140
+ # Returns:
141
+ # -> <rsp>ok</rsp>
142
+ # Authentication
143
+ # -> Authentication is required.
144
+ ######################
145
+ # @Created : DEC/31/2008
146
+ # @LastRefactor : DEC/31/2008
147
+ # @Author : Monther Abushaikh <abushaikh@gmail.com>
148
+ #######################################################
149
+ ### Auto-generated using method_missing ####
150
+
151
+ #######################################################
152
+ # setCaption
153
+ # -> Set a new caption for a photo (overwrites previous caption)
154
+ # Parameters
155
+ # * int media_id (required) - Set the title of this photo.
156
+ # * string caption (required) - The new caption.
157
+ # Returns:
158
+ # -> <rsp>ok</rsp>
159
+ # Authentication
160
+ # -> Authentication is required.
161
+ ######################
162
+ # @Created : DEC/31/2008
163
+ # @LastRefactor : DEC/31/2008
164
+ # @Author : Monther Abushaikh <abushaikh@gmail.com>
165
+ #######################################################
166
+ ### Auto-generated using method_missing ####
167
+
168
+
169
+ end ## end class
170
+ end ## end Advanced
171
+ end ## end ikbis
@@ -0,0 +1,50 @@
1
+ module Ikbis
2
+ module Advanced
3
+
4
+ class Test < Ikbis::Advanced::Base
5
+ def echo(options={})
6
+ options.merge!(:what => "ikbis.test.echo")
7
+ options.merge!(:how => 'xml') unless options.has_key?(:how)
8
+ response = @access_token.post('/api/rest' , options)
9
+ return response.body
10
+ end ## end test_echo
11
+
12
+ #######################################################
13
+ # ikbis.test.login
14
+ # -> Is the user logged in?
15
+ # Returns:
16
+ # -> <profile>
17
+ # -> <id>25874</id>
18
+ # -> <username>moski_doski</username>
19
+ # -> </profile>
20
+ # Error Codes:
21
+ # -> 205: Not Logged in
22
+ ######################
23
+ # @Created : DEC/31/2007
24
+ # @LastRefactor : DEC/31/2007
25
+ # @Author : Monther Abushaikh <abushaikh@gmail.com>
26
+ #######################################################
27
+ def login(options = {})
28
+ options.merge!(:what => "ikbis.test.login")
29
+ options.merge!(:how => "xml") unless options.has_key?(:how)
30
+ return send_request(options)
31
+ end ## end test_login
32
+
33
+ #######################################################
34
+ # ikbis.test.ping
35
+ # -> This is just a simple ping test...
36
+ # Returns:
37
+ # -> <rsp>ok</rsp>
38
+ ######################
39
+ # @Created : DEC/31/2007
40
+ # @LastRefactor : DEC/31/2007
41
+ # @Author : Monther Abushaikh <abushaikh@gmail.com>
42
+ #######################################################
43
+ def ping(options = {})
44
+ options.merge!(:what => "ikbis.test.ping")
45
+ options.merge!(:how => 'xml') unless options.has_key?(:how)
46
+ return send_request(options)
47
+ end ## end test_ping
48
+ end
49
+ end ## end Advanced
50
+ end ## end ikbis
@@ -0,0 +1,164 @@
1
+ require 'open-uri'
2
+ require 'net/http'
3
+ require 'yaml'
4
+ require 'cgi'
5
+ require 'net/http/post/multipart'
6
+ module Ikbis
7
+ module Advanced
8
+ class Upload < Ikbis::Advanced::Base
9
+
10
+ class CouldNotUpload < Exception; end
11
+ class CouldNotAuthenticate < CouldNotUpload; end
12
+ class InvalidUploadFile < CouldNotUpload; end
13
+ class InvalidMediaType < Exception; end
14
+
15
+ #######################################################
16
+ # Set the class extention string for this class.
17
+ ######################
18
+ # @Created : Jan/19/2009
19
+ # @LastRefactor : Jan/19/2009
20
+ # @Author : Monther Abushaikh <abushaikh@gmail.com>
21
+ #######################################################
22
+ def initialize
23
+ @class_extention = "ikbis.upload"
24
+ super ### call the media initialize function.
25
+ end
26
+
27
+ #######################################################
28
+ # Sends a multipart/form POST request to the server
29
+ # containing all the required fields for uploading media.
30
+ #
31
+ # It made no sense for this method to follow its siblings behaviour
32
+ # by delegating a send request to Ikbis::Advanced::Base module
33
+ # with the req params, like the other modules are doing since this
34
+ # request is handled by Net::HTTP and NOT HTTParty.
35
+ #
36
+ # The uploaded file is being parsed into a multi-part/form compatible
37
+ # request object by the gem `multipart-post' by Nick Sieger, cheers
38
+ # to him for making this an easy task.
39
+ #
40
+ # Params:
41
+ # * string file_path =>
42
+ # must either be a full path or a relative one to the upload file
43
+ # * hash options
44
+ # {
45
+ # * string :title => media title
46
+ # * string :caption => media caption, defaults to title if not specified
47
+ # * string enum :type => !"media"|"image"|"video"
48
+ # * string :tags => space delimited media tag(s)
49
+ # * string enum :permission => !"public"|"private"|"shared"
50
+ # }
51
+ # `!' implies default value
52
+ # note: ALL parameters are REQUIRED
53
+ #
54
+ # Usage ex:
55
+ # uploader = Ikbis::Advanced::Uploader.new # must create an object since OAuth is required
56
+ # uploader.oauth_authentication("ikbis.yml")
57
+ # uploader.upload(
58
+ # "http://www.mydomain.com/foo.png",
59
+ # {
60
+ # :title => "FooBAR",
61
+ # :caption => "FooBAR Cap'n",
62
+ # :tags => "hello world",
63
+ # :permission => "public"
64
+ # })
65
+ ######################
66
+ # @Created : Jan/19/2009
67
+ # @LastRefactor : Jan/13/2010
68
+ # @Author : Monther Abushaikh <abushaikh@gmail.com>
69
+ #######################################################
70
+ IMAGE = "image"
71
+ VIDEO = "video"
72
+ MEDIA = "media"
73
+ @@image_types = [ "jpg", "jpeg", "png", "svg", "gif", "bmp" ]
74
+ @@video_types = [ "flv", "wmv", "avi", "mpeg", "3gp", "3g2", "asf", "swf", "mpg", "rm", "3gpp", "mp4", "asp", "mov" ]
75
+
76
+ def uploadFile(file_path, options)
77
+ puts "|------------------------ Uploading ------------------------|"
78
+ begin
79
+ # open file for uploading
80
+ begin
81
+ file = File.new(file_path)
82
+ rescue
83
+ raise InvalidUploadFile
84
+ end
85
+
86
+ url = URI.parse('http://localhost:3000/api/medias')
87
+
88
+ puts "| Initiating POST request to `#{url.request_uri}'"
89
+ req = Net::HTTP::Post.new(url.request_uri)
90
+
91
+ puts "| Constructing File object"
92
+ req = Net::HTTP::Post::Multipart.new url.path,
93
+ { "file" => UploadIO.new(file, mime_type(file), file.path),
94
+ "title" => options[:title],
95
+ "caption" => options[:caption],
96
+ "type" => type(file),
97
+ "tags" => options[:tags],
98
+ "permission" => options[:permission]
99
+ }
100
+
101
+ puts "| Authenticating..."
102
+ begin
103
+ @consumer.sign!(req, @access_token)
104
+ rescue
105
+ raise CouldNotAuthenticate
106
+ end
107
+
108
+ puts "| Initiating connection with `#{url.host}:#{url.port}'"
109
+ res = ""
110
+
111
+ Net::HTTP.new(url.host, url.port).start do |http|
112
+ print "| Processing request..."
113
+ res = http.request(req)
114
+ print " done!\n"
115
+ end
116
+
117
+ puts "| Upload request sent successfully:"
118
+ puts "| Request URI -> #{url.request_uri}"
119
+ puts "| Response -> #{res}"
120
+
121
+ rescue InvalidMediaType
122
+ print "| File format not supported. Supported types: "
123
+ print "\n| Images => "
124
+ print @@image_types.join(", ")
125
+ print "\n| Videos => "
126
+ print @@video_types.join(", ")
127
+ print "\n"
128
+ rescue CouldNotAuthenticate
129
+ puts "| Error while authenticating, have you run oauth_authenticate() ?"
130
+ rescue InvalidUploadFile
131
+ puts "| An error occured processing the file you input, please make sure the file is valid."
132
+ rescue
133
+ puts "| Upload failed with `#{$!}'\n"
134
+ raise CouldNotUpload
135
+ end
136
+
137
+ puts "|------------------------ --------- ------------------------|"
138
+
139
+ end
140
+
141
+ private
142
+
143
+ # quick and dirty method for determining mime type of uploaded file
144
+ def mime_type(file)
145
+ case
146
+ when file =~ /\.jpg/ then 'image/jpg'
147
+ when file =~ /\.gif$/ then 'image/gif'
148
+ when file =~ /\.png$/ then 'image/png'
149
+ else 'application/octet-stream'
150
+ end
151
+ end
152
+
153
+ def type(file)
154
+ ext = File.extname(file.path).gsub(".", "")
155
+
156
+ return IMAGE if @@image_types.include?(ext)
157
+ return VIDEO if @@video_types.include?(ext)
158
+
159
+ raise InvalidMediaType
160
+ end
161
+
162
+ end ## end class
163
+ end ## end Advanced
164
+ end ## end ikbis
@@ -0,0 +1,172 @@
1
+ module Ikbis
2
+ module Advanced
3
+ class Video < Ikbis::Advanced::Media
4
+
5
+ #######################################################
6
+ # Set the class extention string for this class.
7
+ ######################
8
+ # @Created : Jan/19/2009
9
+ # @LastRefactor : Jan/19/2009
10
+ # @Author : Moski
11
+ #######################################################
12
+ def initialize
13
+ @class_extention = "ikbis.videos"
14
+ super ### call the media initialize function.
15
+ end
16
+
17
+
18
+ #######################################################
19
+ # getUploadedList
20
+ # -> This gets a list of videos uploaded by the specified user.
21
+ # -> If the calling user is logged in, this will return information that calling
22
+ # -> user has access to (including private videos). If the calling user is not authenticated,
23
+ # -> this will only return public information, or a permission denied error if none is available.
24
+ #
25
+ # Parameters
26
+ # * string username- ex.(moski_doski)
27
+ # * options:
28
+ # * int page - Which page to show.
29
+ # * int per_page - How many results per page?
30
+ # * string how - xml or json or php
31
+ #
32
+ # ex: getUploadedList('moski_doski' , {:how => 'json'})
33
+ #
34
+ # Returns:
35
+ # -> <videos>
36
+ # <video>
37
+ # <id>106502</id> <title>كيف توكل منسف اردني</title> <caption>كيف توكل منسف اردني </caption> <views>319</views>
38
+ # <thumbnails>
39
+ # <small>http://shots.ikbis.com/video_thumbnail/106502/small/video.jpg</small>
40
+ # <thumb> http://shots.ikbis.com/video_thumbnail/106502/thumb/video.jpg </thumb>
41
+ # <medium_crop>http://shots.ikbis.com/video_thumbnail/106502/medium_crop/video.jpg</medium_crop>
42
+ # <medium>http://shots.ikbis.com/video_thumbnail/106502/medium/video.jpg</medium>
43
+ # <screen>http://shots.ikbis.com/video_thumbnail/106502/screen/video.jpg</screen>
44
+ # </thumbnails>
45
+ # </video>
46
+ # </videos>
47
+ #
48
+ # Authentication
49
+ # -> Authentication is not required.
50
+ ######################
51
+ # @Created : Jan/19/2009
52
+ # @LastRefactor : Jan/19/2009
53
+ # @Author : Moski
54
+ #######################################################
55
+ ### Auto-generated using method_missing ####
56
+
57
+
58
+ #######################################################
59
+ # getInfo
60
+ # -> Get all kinds of information about a video
61
+ # -> If the calling user is logged in, this will return information
62
+ # -> that calling user has access to (including private videos).
63
+ # -> If the calling user is not authenticated, this will only return
64
+ # public information, or a permission denied error if none is available.
65
+ # Parameters
66
+ # * int media_id (required) - Get information from this video
67
+ #
68
+ # ex: getInfo('moski_doski' , {:how => 'json'})
69
+ #
70
+ # Returns:
71
+ # -> <video>
72
+ # <id>110774</id>
73
+ # <title> the reason</title>
74
+ # <caption>\r\nthe reason\r\n</caption>
75
+ # <views>136</views>
76
+ # <category></category>
77
+ # <owner>moski_doski</owner>
78
+ # <comments>0</comments>
79
+ # <rating>0</rating>
80
+ # <thumbnails>
81
+ # <small>http://shots.ikbis.com/video_thumbnail/110774/small/video.jpg</small>\n
82
+ # <thumb>http://shots.ikbis.com/video_thumbnail/110774/thumb/video.jpg</thumb>\n
83
+ # <medium_crop>http://shots.ikbis.com/video_thumbnail/110774/medium_crop/video.jpg</medium_crop>
84
+ # ..........
85
+ # </thumbnails>
86
+ # </video>
87
+ #
88
+ # Authentication
89
+ # -> Authentication is not required.
90
+ ######################
91
+ # @Created : Jan/19/2009
92
+ # @LastRefactor : Jan/19/2009
93
+ # @Author : Moski
94
+ #######################################################
95
+ ### Auto-generated using method_missing ####
96
+
97
+
98
+ #######################################################
99
+ # getThumbnailUrl(media_id)
100
+ # -> Get a thumbnail URL for a given video/size
101
+ # ->
102
+ # Parameters
103
+ # * int media_id (required) - Get information from this video
104
+ # * thumbnail_size:
105
+ # small "70x70" and crop => "1:1"
106
+ # thumb "90x90" and crop => "1:1"
107
+ # medium_crop "144x144" and crop => "1:1"
108
+ # medium "240x240" and no crop
109
+ # screen "420x420" and no crop
110
+ # all return all sizes
111
+ #
112
+ # ex: getThumbnailUrl(media_id , {:how => 'json'})
113
+ #
114
+ # Returns:
115
+ # -> <thumbnails>
116
+ # <small>http://shots.ikbis.com/video_thumbnail/110774/small/video.jpg</small>\n
117
+ # <thumb>http://shots.ikbis.com/video_thumbnail/110774/thumb/video.jpg</thumb>\n
118
+ # <medium_crop>http://shots.ikbis.com/video_thumbnail/110774/medium_crop/video.jpg</medium_crop>
119
+ # ..........
120
+ # </thumbnails>
121
+ # Authentication
122
+ # -> Authentication is not required.
123
+ ######################
124
+ # @Created : Jan/19/2009
125
+ # @LastRefactor : Jan/19/2009
126
+ # @Author : Moski
127
+ #######################################################
128
+ ### Auto-generated using method_missing ####
129
+
130
+
131
+ #######################################################
132
+ # setTitle
133
+ # -> Set the title of a video (overwrites previous title)
134
+ # Parameters
135
+ # * int media_id (required) - Set the title of this video.
136
+ # * string title (required) - The new title. 128 is the max length for this field, any longer and it will be trimmed.
137
+ #
138
+ # ex: getThumbnailUrl(media_id , {:how => 'json'})
139
+ #
140
+ # Returns:
141
+ # -> <rsp>ok</rsp>
142
+ # Authentication
143
+ # -> Authentication is required.
144
+ ######################
145
+ # @Created : DEC/31/2007
146
+ # @LastRefactor : DEC/31/2007
147
+ # @Author : Moski
148
+ #######################################################
149
+ ### Auto-generated using method_missing ####
150
+
151
+ #######################################################
152
+ # setCaption
153
+ # -> Set a new caption for a video (overwrites previous caption)
154
+ # Parameters
155
+ # * int media_id (required) - Set the title of this video.
156
+ # * string caption (required) - The new caption.
157
+ # Returns:
158
+ # -> <rsp>ok</rsp>
159
+ # Authentication
160
+ # -> Authentication is required.
161
+ ######################
162
+ # @Created : Jan/19/2009
163
+ # @LastRefactor : Jan/19/2009
164
+ # @Author : Moski
165
+ #######################################################
166
+ ### Auto-generated using method_missing ####
167
+
168
+
169
+
170
+ end ## end video
171
+ end ## end Advanced
172
+ end ## end ikbis