mush 0.2.2 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99555f67ace862b592bbd9fcec7c4d71cc7a895f
4
- data.tar.gz: 5a478d3e69baeb2722599d198ae457235d62e678
3
+ metadata.gz: 32c873cff6dfdbd0efc9d234da57dab78ddb5011
4
+ data.tar.gz: 87905881d0dc52b1753968a13726bbded4301d73
5
5
  SHA512:
6
- metadata.gz: c58d7657871d0fa2bc573927568be7487d67885d4e21b7ba6b19a858b6be01ab8f8cc85ae3fb920239e31c7a6308bba368fa272ab2401f82ce4cb3b756a39fe2
7
- data.tar.gz: 0bf457908098139535358be7eabfa0fb851013ee86a833b57ef209376f061cb1cde44a7781365dfd9f1e41ce33572be4adb06a8a3235833859bcd7d0643dda07
6
+ metadata.gz: 58828a92c0c7914d63970c7923d675a5f87e1afa1b0c400b9073ea097ded20c1f554344d1d58a71c96f2070ed3be77facab8cc90f4b062c010aab443d5165c5b
7
+ data.tar.gz: 1d62875e077fcdbbf98e50ee0288ee0f3cee2150b71bbf7c296799232c77f891b823907a45dcd4c0c8848508daa58849c4c01a1b7767135deba881196ab5323e
data/README.md CHANGED
@@ -23,11 +23,15 @@ Supported services
23
23
  * bit.ly
24
24
  * is.gd
25
25
 
26
- and thanks to [Noel Dellofano](https://github.com/pinkvelociraptor) from [ZenDesk](http://www.zendesk.com/)
26
+ and thanks to [Noel Dellofano](https://github.com/pinkvelociraptor) from [ZenDesk](http://www.zendesk.com/):
27
27
 
28
28
  * ow.ly
29
29
  * custom service
30
30
 
31
+ and thanks to [Alex Rodionov](https://github.com/p0deje):
32
+
33
+ * zae.bz
34
+
31
35
  Usage as a command line utility
32
36
  -------------------------------
33
37
 
@@ -37,6 +41,8 @@ Usage as a command line utility
37
41
 
38
42
  $ owly -k apikey -u foo.raflabs.com
39
43
 
44
+ $ zaebz http://foo.raflabs.com/
45
+
40
46
  $ shorten -s "http://chop.ws/index.php?api=1&return_url_text=1&longUrl={{url}}" -u foo.raflabs.com
41
47
 
42
48
  **NOTE:** _The 'shorten' command uses <code>Mush::Service::Custom</code> and currently it only works with services that accept 'get' as method (not 'post') and with services that return only the shortened url not a full html page_
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDOUT.sync = true
4
+
5
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
6
+
7
+ require 'rubygems'
8
+ require 'optparse'
9
+ require 'mush'
10
+
11
+ ORIGINAL_ARGV = ARGV.dup
12
+
13
+ options = {}
14
+
15
+ opts = OptionParser.new do |opts|
16
+ opts.banner = <<-EOF
17
+ Usage:
18
+ zaebz URL
19
+
20
+ Options:
21
+ EOF
22
+
23
+ opts.on("-v", "--version", "Print the version number and exit") do
24
+ options[:version] = true
25
+ end
26
+ end
27
+
28
+ opts.parse!
29
+
30
+ if options[:version]
31
+ abort("Version " + Mush.version)
32
+ end
33
+
34
+ # validate
35
+ unless url = ORIGINAL_ARGV.first
36
+ puts opts
37
+ abort
38
+ end
39
+
40
+ puts Mush::Services::Zaebz.new.shorten(url)
@@ -1,5 +1,5 @@
1
1
  module Mush
2
-
2
+
3
3
  # This is the class all the services must inherit from.
4
4
  class Service
5
5
  include HTTParty
@@ -8,22 +8,26 @@ module Mush
8
8
  def get(path, options = {})
9
9
  self.class.get(path, options)
10
10
  end
11
-
11
+
12
+ def post(path, payload, options = {})
13
+ self.class.post(path, options.merge(:body => payload))
14
+ end
15
+
12
16
  def shorten(*)
13
17
  raise InterfaceMethodNotImplementedError.new("Service#shorten must be overridden in subclasses")
14
18
  end
15
-
19
+
16
20
  def authorize(args = {})
17
21
  raise InvalidAuthorizationData.new("Invalid Authorization Data, please provide both login and apikey") unless valid_authorization_data? args
18
22
  @login = options[:login]
19
23
  @apikey = options[:apikey]
20
24
  end
21
-
25
+
22
26
  protected
23
27
  def valid_authorization_data?(data)
24
28
  [:login, :apikey].all? { |key| data.key? key }
25
29
  end
26
-
30
+
27
31
  def self.authorizable_with(*options)
28
32
  raise InvalidAuthorizationFields.new("Should provide fields to authorize with") if options.empty?
29
33
  @params_to_authorize = options
@@ -31,7 +35,7 @@ module Mush
31
35
  options.each { |o| attr_accessor o.to_sym }
32
36
  end
33
37
  end
34
-
38
+
35
39
  end
36
-
37
- end
40
+
41
+ end
@@ -0,0 +1,16 @@
1
+ module Mush
2
+ module Services
3
+ class Zaebz < Service
4
+ base_uri 'http://zae.bz'
5
+
6
+ def shorten(url)
7
+ if url.empty? || url !~ %r(^https?://.+)
8
+ raise InvalidURI.new("Please provide a valid URI")
9
+ end
10
+
11
+ post('/', { :url => url }).body.match(/href="(.+)"/)[1]
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -2,17 +2,18 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: mush 0.3.0 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "mush"
8
- s.version = "0.2.2"
9
+ s.version = "0.3.0"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
12
  s.authors = ["Rafael Magana"]
12
- s.date = "2013-09-13"
13
+ s.date = "2014-02-08"
13
14
  s.description = "A gem to shorten URLs using different services, it has one command-line utility for each supported service and one for custom shorteners called 'shorten'."
14
15
  s.email = "raf.magana@gmail.com"
15
- s.executables = ["bitly", "isgd", "mush", "owly", "shorten"]
16
+ s.executables = ["bitly", "isgd", "mush", "owly", "shorten", "zaebz"]
16
17
  s.extra_rdoc_files = [
17
18
  "LICENSE",
18
19
  "README.md"
@@ -31,6 +32,7 @@ Gem::Specification.new do |s|
31
32
  "bin/mush",
32
33
  "bin/owly",
33
34
  "bin/shorten",
35
+ "bin/zaebz",
34
36
  "lib/mush.rb",
35
37
  "lib/mush/authenticated_service.rb",
36
38
  "lib/mush/errors.rb",
@@ -39,13 +41,14 @@ Gem::Specification.new do |s|
39
41
  "lib/mush/services/custom.rb",
40
42
  "lib/mush/services/isgd.rb",
41
43
  "lib/mush/services/owly.rb",
44
+ "lib/mush/services/zaebz.rb",
42
45
  "mush.gemspec",
43
46
  "test/helper.rb",
44
47
  "test/test_mush.rb"
45
48
  ]
46
49
  s.homepage = "http://github.com/rafmagana/mush"
47
50
  s.require_paths = ["lib"]
48
- s.rubygems_version = "2.0.6"
51
+ s.rubygems_version = "2.1.5"
49
52
  s.summary = "A multiple service URL shortener gem with command-line utilities"
50
53
 
51
54
  if s.respond_to? :specification_version then
@@ -19,6 +19,10 @@ describe Mush do
19
19
  it "add an instance method called 'get' that wrappes the HTTParty#get method" do
20
20
  assert Mush::Service.new.respond_to? :get
21
21
  end
22
+
23
+ it "add an instance method called 'post' that wrappes the HTTParty#get method" do
24
+ assert Mush::Service.new.respond_to? :post
25
+ end
22
26
  end
23
27
 
24
28
  describe "All Services" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Magana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-13 00:00:00.000000000 Z
11
+ date: 2014-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -117,6 +117,7 @@ executables:
117
117
  - mush
118
118
  - owly
119
119
  - shorten
120
+ - zaebz
120
121
  extensions: []
121
122
  extra_rdoc_files:
122
123
  - LICENSE
@@ -135,6 +136,7 @@ files:
135
136
  - bin/mush
136
137
  - bin/owly
137
138
  - bin/shorten
139
+ - bin/zaebz
138
140
  - lib/mush.rb
139
141
  - lib/mush/authenticated_service.rb
140
142
  - lib/mush/errors.rb
@@ -143,6 +145,7 @@ files:
143
145
  - lib/mush/services/custom.rb
144
146
  - lib/mush/services/isgd.rb
145
147
  - lib/mush/services/owly.rb
148
+ - lib/mush/services/zaebz.rb
146
149
  - mush.gemspec
147
150
  - test/helper.rb
148
151
  - test/test_mush.rb
@@ -165,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
168
  version: '0'
166
169
  requirements: []
167
170
  rubyforge_project:
168
- rubygems_version: 2.0.6
171
+ rubygems_version: 2.1.5
169
172
  signing_key:
170
173
  specification_version: 4
171
174
  summary: A multiple service URL shortener gem with command-line utilities