mediaplug2-ruby 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,4 +8,10 @@ of MediaPlug URLs.
8
8
 
9
9
  mp = MediaPlug.new("mp.yourserver.com")
10
10
  mp.image('http://some.url', :jpg).resize('>100x>100').crop('100x100').to_s
11
- # => http://mp.yourserver.com/mp/get?mpsrc=http%3A%2F%2Fsome.url&mpaction=resize%20width%3D%3E100%20height%3D%3E100%20format%3Djpg%3Bcrop%20location%3Dcenter%20width%3D100%20height%3D100%20format%3Djpg
11
+ # => http://mp.yourserver.com/mp/get?mpsrc=http%3A%2F%2Fsome.url&mpaction=resize%20width%3D%3E100%20height%3D%3E100%20format%3Djpg%3Bcrop%20location%3Dcenter%20width%3D100%20height%3D100%20format%3Djpg
12
+
13
+ Now Mediaplug2 server allows you to create shorten Url:
14
+ Write down your access id from your profile in Mediaplug Mangement Portal:
15
+
16
+ mp = MediaPlug.new('video.gomediaplug.com', your_access_id)
17
+ mp.image('http://some.url', :jpg).resize('>100x>100').crop('100x100').shorten
@@ -1,2 +1,3 @@
1
1
  require 'mediaplug/mediaplug_url'
2
- require 'mediaplug/mediaplug'
2
+ require 'mediaplug/mediaplug'
3
+ require 'mediaplug/client'
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+ require 'uri'
4
+ require 'cgi'
5
+ module Mediaplug
6
+ class Client
7
+ include HTTParty
8
+ format :json
9
+ def initialize(server, access_id)
10
+ self.class.base_uri server
11
+ @access_id = access_id
12
+ end
13
+
14
+ def shorten(input, opts={})
15
+ result = get_result("/urls", 'url[url]' => input)['url']['code']
16
+ result = self.class.base_uri+"/"+result
17
+ rescue
18
+ raise MediaplugError.new('error shorten the url.', 100)
19
+ end
20
+
21
+ def get_result(resource='', args={})
22
+ args = args.merge({'url[access_id]' => @access_id})
23
+ begin
24
+ result = self.class.post(resource, :query => args).parsed_response
25
+ rescue Exception => e
26
+ result = {'errorMessage' => e.message, 'errorCode' => 69, 'statusCode' => 'ERROR'}
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ class MediaplugError < StandardError
34
+ attr_reader :code
35
+ alias :msg :message
36
+ def initialize(msg, code)
37
+ @code = code
38
+ super("#{msg} - '#{code}'")
39
+ end
40
+ end
@@ -1,28 +1,27 @@
1
- require 'bitly'
2
1
  class MediaPlug
3
2
  class InvalidAction < StandardError; end
4
- class BitLyCredsMissing < StandardError; end
3
+ class AccessIdMissing < StandardError; end
5
4
  attr_accessor :server
6
5
 
7
6
  # Server is the domain of the MediaPlug server, e.g. "mp.yourdomain.com"
8
- def initialize(server, bitly_login = nil, bitly_key = nil)
7
+ def initialize(server, mediaplug_access_id=nil)
9
8
  self.server = server
10
- @bitly = Bitly.new(bitly_login, bitly_key) if bitly_login && bitly_key
9
+ @access_id = mediaplug_access_id
11
10
  end
12
11
 
13
12
  # Generates an image-formatted MediaPlugURL from the specified URL
14
13
  def image(url, format='jpg')
15
- MediaPlugURL.new(server,:image,url,format, @bitly)
14
+ MediaPlugURL.new(server,:image,url,format, @access_id)
16
15
  end
17
16
 
18
17
  # Generates a video-formatted MediaPlugURL from the specified URL
19
18
  def video(url, format='flv')
20
- MediaPlugURL.new(server,:video,url,format, @bitly)
19
+ MediaPlugURL.new(server,:video,url,format, @access_id)
21
20
  end
22
21
 
23
22
  # Generates an audio-formatted MediaPlugURL from the specified URL
24
23
  def audio(url, format='mp3')
25
- MediaPlugURL.new(server,:audio,url,format, @bitly)
24
+ MediaPlugURL.new(server,:audio,url,format, @access_id)
26
25
  end
27
26
 
28
27
  end
@@ -3,17 +3,18 @@
3
3
  # by using its to_s method. It should be instantiated through
4
4
  # the MediaPlug class, not by itself:
5
5
  class MediaPlugURL
6
- def initialize(server, media_type, url, format, bitly)
6
+ def initialize(server, media_type, url, format, access_id)
7
7
  @server = server
8
8
  @media_type = media_type
9
9
  @url = url
10
10
  @format = format
11
- @bitly = bitly
11
+ @access_id = access_id
12
12
  @actions = []
13
13
  end
14
14
  def shorten
15
- raise MediaPlug::BitLyCredsMissing if @bitly.blank?
16
- @bitly.shorten(self.to_s).short_url
15
+ raise MediaPlug::AccessIdMissing if @access_id.blank?
16
+ @mp_shorten ||= Mediaplug::Client.new(@server, @access_id)
17
+ @mp_shorten.shorten(self.to_s)
17
18
  end
18
19
 
19
20
  # <b>Image Only:</b> Resize an image to the dimensions specified. The
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediaplug2-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
4
+ prerelease:
5
+ version: 0.0.4
11
6
  platform: ruby
12
7
  authors:
13
8
  - Michael Bleigh
@@ -16,23 +11,18 @@ autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
13
 
19
- date: 2011-03-23 00:00:00 -05:00
14
+ date: 2011-07-18 00:00:00 -05:00
20
15
  default_executable:
21
16
  dependencies:
22
17
  - !ruby/object:Gem::Dependency
23
- name: bitly
18
+ name: httparty
24
19
  prerelease: false
25
20
  requirement: &id001 !ruby/object:Gem::Requirement
26
21
  none: false
27
22
  requirements:
28
23
  - - ">="
29
24
  - !ruby/object:Gem::Version
30
- hash: 5
31
- segments:
32
- - 0
33
- - 6
34
- - 1
35
- version: 0.6.1
25
+ version: 0.7.4
36
26
  type: :runtime
37
27
  version_requirements: *id001
38
28
  description: A wrapper for the MediaPlug 2 API to give a simple syntax for MediaPlug URL generation.
@@ -52,6 +42,7 @@ files:
52
42
  - lib/mediaplug/mediaplug.rb
53
43
  - lib/mediaplug/mediaplug_url.rb
54
44
  - lib/mediaplug-ruby.rb
45
+ - lib/mediaplug/client.rb
55
46
  has_rdoc: true
56
47
  homepage: http://github.com/intridea/mediaplug2-ruby
57
48
  licenses: []
@@ -67,23 +58,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
58
  requirements:
68
59
  - - ">="
69
60
  - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
61
  version: "0"
74
62
  required_rubygems_version: !ruby/object:Gem::Requirement
75
63
  none: false
76
64
  requirements:
77
65
  - - ">="
78
66
  - !ruby/object:Gem::Version
79
- hash: 3
80
- segments:
81
- - 0
82
67
  version: "0"
83
68
  requirements: []
84
69
 
85
70
  rubyforge_project:
86
- rubygems_version: 1.3.7
71
+ rubygems_version: 1.6.2
87
72
  signing_key:
88
73
  specification_version: 3
89
74
  summary: A wrapper for the MediaPlug 2 API to give a simple syntax for MediaPlug URL generation.