ruby-bitly 0.1.3 → 0.1.5.beta3

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.
File without changes
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.1.4
2
+
3
+ - Code improvements
4
+
1
5
  # 0.1.3
2
6
 
3
7
  - Copy to clipboard for Mac users
@@ -7,4 +11,4 @@
7
11
  - Moving read file ~/.bitly from Bitly class to command line script
8
12
  - Using Bitly class is an OpenStruct
9
13
  - Simplified code
10
- - bit.ly credentials as parameters
14
+ - bit.ly credentials as parameters
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby-bitly.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby-bitly (0.1.5.beta3)
5
+ rest-client (~> 1.6.1)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ addressable (2.2.6)
11
+ crack (0.1.8)
12
+ diff-lcs (1.1.2)
13
+ mime-types (1.16)
14
+ rake (0.8.7)
15
+ rest-client (1.6.1)
16
+ mime-types (>= 1.16)
17
+ rspec (2.6.0)
18
+ rspec-core (~> 2.6.0)
19
+ rspec-expectations (~> 2.6.0)
20
+ rspec-mocks (~> 2.6.0)
21
+ rspec-core (2.6.4)
22
+ rspec-expectations (2.6.0)
23
+ diff-lcs (~> 1.1.2)
24
+ rspec-mocks (2.6.0)
25
+ vcr (1.10.0)
26
+ webmock (1.6.4)
27
+ addressable (> 2.2.5, ~> 2.2)
28
+ crack (>= 0.1.7)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ rake (~> 0.8.7)
35
+ rspec (~> 2.6.0)
36
+ ruby-bitly!
37
+ vcr (~> 1.10.0)
38
+ webmock (~> 1.6.4)
data/README.rdoc CHANGED
@@ -1,6 +1,29 @@
1
- = A simple bitly ruby client.
1
+ = A simple bit.ly ruby client.
2
2
 
3
3
  == Examples
4
+ require 'ruby-bitly'
5
+
6
+ bitly = Bitly.shorten("http://rafaeldx7.github.com", "username", "key-here")
7
+
8
+ bitly.url #=> "http://bit.ly/le0JRh"
9
+
10
+ y bitly
11
+ :long_url: http://rafaeldx7.github.com/
12
+ :url: http://bit.ly/le0JRh
13
+ :hash: le0JRh
14
+ :global_hash: micSj7
15
+ :new_hash: 0
16
+ :hash_path: le0JRh
17
+ :status_code: 200
18
+ :status_txt: OK
19
+
20
+ == Command Line Examples
21
+ Usage
22
+ bitly [options] url
23
+
24
+ For help: bitly -h
25
+
26
+ Basic examples:
4
27
  bitly -s http://xlii.com.br
5
28
  bitly -e http://bit.ly/XLII42
6
29
  bitly --user-clicks http://bit.ly/XLII42
@@ -10,12 +33,7 @@
10
33
  bitly -q -s http://xlii.com.br
11
34
  bitly --verbose -e http://bit.ly/XLII42
12
35
 
13
- == Usage
14
- bitly [options] url
15
-
16
- For help: bitly -h
17
-
18
- == Options
36
+ Options
19
37
  -s, --shorten Shorten a long url (default option)
20
38
  -e, --expand Expand a short bitly url
21
39
  -u, --user-clicks Show user clicks from the short bitly url
@@ -29,22 +47,22 @@
29
47
  -q, --quiet Output as little as possible, overrides verbose
30
48
  -V, --verbose Verbose output
31
49
 
32
- == Authentication
50
+ === Authentication
33
51
  bit.ly API require that authentication credentials be supplied.
34
52
 
35
53
  To get started, you'll need a free bit.ly user account and apiKey. Signup at: http://bit.ly/a/sign_up
36
54
  If you already have an account, you can find your apiKey at: http://bit.ly/a/your_api_key
37
-
55
+
38
56
  You can supply credentials as parameters. By example:
39
- bitly -l username -k key-here -s http://xlii.com.br
40
-
57
+ bitly -l <username> -k <key-here> -s http://xlii.com.br
58
+
41
59
  Or you can create the file ~/.bitly (YAML format) with this content:
42
- login: username
43
- key: key-here
60
+ login: <username>
61
+ key: <key-here>
44
62
 
45
63
  == Author
46
64
  rafaeldx7 ~ rafaeldx7(a)gmail.com
47
65
 
48
66
  == Copyright
49
67
  Copyright (c) 2010 rafaeldx7. Licensed under the MIT License:
50
- http://www.opensource.org/licenses/mit-license.php
68
+ http://www.opensource.org/licenses/mit-license.php
data/Rakefile CHANGED
@@ -1,48 +1,7 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ # -*- encoding: utf-8 -*-
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
3
4
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "ruby-bitly"
8
- gem.summary = %Q{This is a simple bit.ly ruby client}
9
- gem.description = %Q{This is a simple bit.ly ruby client}
10
- gem.email = "rafaeldx7@gmail.com"
11
- gem.homepage = "http://github.com/rafaeldx7/ruby-bitly"
12
- gem.authors = ["rafaeldx7"]
13
- gem.add_runtime_dependency "rest-client", "1.6.0"
14
- gem.add_runtime_dependency "json_pure", "1.4.3"
15
- gem.add_development_dependency "rake", "0.8.7"
16
- gem.add_development_dependency "rspec", "1.3.0"
17
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
- end
19
- Jeweler::GemcutterTasks.new
20
- rescue LoadError
21
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
- end
23
-
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs << 'lib' << 'spec'
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
- end
29
-
30
- Spec::Rake::SpecTask.new(:rcov) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.pattern = 'spec/**/*_spec.rb'
33
- spec.rcov = true
34
- end
35
-
36
- task :spec => :check_dependencies
5
+ RSpec::Core::RakeTask.new(:spec)
37
6
 
38
7
  task :default => :spec
39
-
40
- require 'rake/rdoctask'
41
- Rake::RDocTask.new do |rdoc|
42
- version = File.exist?('VERSION') ? File.read('VERSION') : "0.0.0"
43
-
44
- rdoc.rdoc_dir = 'rdoc'
45
- rdoc.title = "ruby-bitly #{version}"
46
- rdoc.rdoc_files.include('README*')
47
- rdoc.rdoc_files.include('lib/**/*.rb')
48
- end
data/bin/bitly CHANGED
@@ -1,16 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
2
3
 
3
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
5
 
5
6
  require 'rubygems'
6
7
  require 'ruby-bitly'
7
- require 'optparse'
8
- require 'readme'
8
+ require 'optparse'
9
9
  require 'ostruct'
10
10
  require 'date'
11
11
 
12
12
  class App
13
- VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
14
13
  ACCOUNT_FILE_PATH = "#{ENV['HOME']}/.bitly"
15
14
 
16
15
  attr_accessor :arguments, :options
@@ -23,28 +22,28 @@ class App
23
22
 
24
23
  def run
25
24
  process_options
26
-
27
- if arguments_valid?
25
+
26
+ if arguments_valid?
28
27
  output_options if options.verbose
29
-
28
+
30
29
  post_process_options and process_arguments
31
-
30
+
32
31
  result = process_command
33
-
32
+
34
33
  puts "#{options.message} #{result}".strip
35
-
34
+
36
35
  copy_to_clipboard(result)
37
36
  else
38
37
  output_help("ERROR: Invalid options", 'examples')
39
38
  end
40
39
  end
41
-
40
+
42
41
  protected
43
-
42
+
44
43
  def copy_to_clipboard(value)
45
44
  system "printf '#{value.strip}' 2> /dev/null | pbcopy 2> /dev/null" if RUBY_PLATFORM[/darwin/]
46
45
  end
47
-
46
+
48
47
  def load_account_data
49
48
  begin
50
49
  account_data = YAML.load(File.read(ACCOUNT_FILE_PATH))
@@ -57,71 +56,75 @@ class App
57
56
  options.key = account_data["key"]
58
57
  end
59
58
  end
60
-
59
+
61
60
  def default_options
62
61
  options.verbose = false
63
62
  options.quiet = false
64
63
  end
65
-
64
+
66
65
  def process_options
67
66
  default_options
68
-
69
- opts = OptionParser.new
70
-
67
+
68
+ opts = OptionParser.new
69
+
71
70
  opts.on('-s', '--shorten') { options.shorten = true; options.message = 'Short url:' }
72
71
  opts.on('-e', '--expand') { options.expand = true; options.message = 'Original url:' }
73
72
  opts.on('-u', '--user-clicks') { options.user_clicks = true; options.message = 'User clicks:' }
74
73
  opts.on('-g', '--global-clicks') { options.global_clicks = true; options.message = 'Global clicks:' }
75
-
74
+
76
75
  opts.on('-l', '--login LOGIN') { |login| options.login = login }
77
76
  opts.on('-k', '--key KEY') { |key| options.key = key }
78
-
77
+
79
78
  opts.on('-v', '--version') { output_version ; exit 0 }
80
79
  opts.on('-h', '--help') { output_help }
81
80
  opts.on('-V', '--verbose') { options.verbose = true }
82
81
  opts.on('-q', '--quiet') { options.quiet = true; options.verbose = false }
83
-
82
+
84
83
  opts.parse!(arguments) rescue return false
85
84
  end
86
-
85
+
87
86
  def post_process_options
88
87
  # Bitly API Login / Key
89
88
  load_account_data unless options.login and options.key
90
-
89
+
91
90
  # Default option: --shorten
92
91
  options.shorten = true and options.message = 'Short url:' unless options.expand or options.user_clicks or options.global_clicks
93
-
92
+
94
93
  # Message empty if option quiet exists
95
94
  options.message = '' if options.quiet
96
95
  end
97
96
 
98
97
  def output_options
99
98
  puts "Options:\n"
100
-
101
- options.marshal_dump.each do |name, val|
99
+
100
+ options.marshal_dump.each do |name, val|
102
101
  puts " #{name} = #{val}"
103
102
  end
104
-
103
+
105
104
  puts " URL: #{arguments.first}\n"
106
105
  end
107
106
 
108
107
  def arguments_valid?
109
108
  arguments.length == 1
110
109
  end
111
-
110
+
112
111
  def process_arguments
113
112
  end
114
-
113
+
115
114
  def output_help(message = nil, section = "")
116
115
  puts message if message
117
-
118
- Readme::usage(section) #exits app
116
+
117
+ File.open(File.join(File.dirname(__FILE__), '..', 'README.rdoc'), "r") do |infile|
118
+ while (line = infile.gets)
119
+ puts line
120
+ end
121
+ end
119
122
  end
120
-
123
+
121
124
  def output_version
122
- puts "bitly version #{VERSION.chomp} [gem ruby-bitly]"
125
+ puts "bitly version #{Bitly::VERSION} [gem ruby-bitly]"
123
126
  end
124
-
127
+
125
128
  def process_command
126
129
  return Bitly.shorten(arguments.first, options.login, options.key).url if options.shorten
127
130
  return Bitly.expand(arguments.first, options.login, options.key).long_url if options.expand
@@ -0,0 +1,36 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: http://api.bit.ly:80/v3/expand
6
+ body: shortURL=http%3A%2F%2Fgoogle.com&login=rafaeldx7&apiKey=R_59c1b174b21d92b2beeb4787a6d7ebaf
7
+ headers:
8
+ accept:
9
+ - "*/*; q=0.5, application/xml"
10
+ accept-encoding:
11
+ - gzip, deflate
12
+ content-length:
13
+ - "90"
14
+ content-type:
15
+ - application/x-www-form-urlencoded
16
+ response: !ruby/struct:VCR::Response
17
+ status: !ruby/struct:VCR::ResponseStatus
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ server:
22
+ - nginx
23
+ date:
24
+ - Sat, 28 May 2011 17:22:28 GMT
25
+ content-type:
26
+ - application/json; charset=utf-8
27
+ connection:
28
+ - keep-alive
29
+ mime-version:
30
+ - "1.0"
31
+ content-length:
32
+ - "131"
33
+ body: |
34
+ { "status_code": 200, "status_txt": "OK", "data": { "expand": [ { "error": "NOT_FOUND", "short_url": "http:\/\/google.com" } ] } }
35
+
36
+ http_version: "1.1"
@@ -0,0 +1,36 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: http://api.bit.ly:80/v3/expand
6
+ body: shortURL=http%3A%2F%2Fbit.ly%2FbcvNe5&login=rafaeldx7&apiKey=R_59c1b174b21d92b2beeb4787a6d7ebaf
7
+ headers:
8
+ accept:
9
+ - "*/*; q=0.5, application/xml"
10
+ accept-encoding:
11
+ - gzip, deflate
12
+ content-length:
13
+ - "95"
14
+ content-type:
15
+ - application/x-www-form-urlencoded
16
+ response: !ruby/struct:VCR::Response
17
+ status: !ruby/struct:VCR::ResponseStatus
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ server:
22
+ - nginx
23
+ date:
24
+ - Sat, 28 May 2011 17:22:27 GMT
25
+ content-type:
26
+ - application/json; charset=utf-8
27
+ connection:
28
+ - keep-alive
29
+ mime-version:
30
+ - "1.0"
31
+ content-length:
32
+ - "197"
33
+ body: |
34
+ { "status_code": 200, "status_txt": "OK", "data": { "expand": [ { "short_url": "http:\/\/bit.ly\/bcvNe5", "long_url": "http:\/\/google.com", "user_hash": "bcvNe5", "global_hash": "zzzzzzz" } ] } }
35
+
36
+ http_version: "1.1"
@@ -0,0 +1,30 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.bit.ly:80/v3/clicks?apiKey=R_59c1b174b21d92b2beeb4787a6d7ebaf&login=rafaeldx7&shortUrl=http://bit.ly/xlii42
6
+ body:
7
+ headers:
8
+ accept:
9
+ - "*/*; q=0.5, application/xml"
10
+ accept-encoding:
11
+ - gzip, deflate
12
+ response: !ruby/struct:VCR::Response
13
+ status: !ruby/struct:VCR::ResponseStatus
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ server:
18
+ - nginx
19
+ date:
20
+ - Sat, 28 May 2011 17:22:28 GMT
21
+ content-type:
22
+ - application/json; charset=utf-8
23
+ connection:
24
+ - keep-alive
25
+ content-length:
26
+ - "187"
27
+ etag:
28
+ - "\"20a0b40a65714ad5a2440caad07fd5c5518584b7\""
29
+ body: "{\"status_code\": 200, \"data\": {\"clicks\": [{\"short_url\": \"http://bit.ly/xlii42\", \"global_hash\": \"cunZEP\", \"user_clicks\": 1, \"user_hash\": \"cT1Izu\", \"global_clicks\": 1}]}, \"status_txt\": \"OK\"}"
30
+ http_version: "1.1"
@@ -0,0 +1,34 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: http://api.bit.ly:80/v3/shorten
6
+ body: longURL=http%3A%2F%2Fbit.ly%2FbcvNe5&login=rafaeldx7&apiKey=R_59c1b174b21d92b2beeb4787a6d7ebaf
7
+ headers:
8
+ accept:
9
+ - "*/*; q=0.5, application/xml"
10
+ accept-encoding:
11
+ - gzip, deflate
12
+ content-length:
13
+ - "94"
14
+ content-type:
15
+ - application/x-www-form-urlencoded
16
+ response: !ruby/struct:VCR::Response
17
+ status: !ruby/struct:VCR::ResponseStatus
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ server:
22
+ - nginx
23
+ date:
24
+ - Sat, 28 May 2011 17:22:26 GMT
25
+ content-type:
26
+ - application/json; charset=utf-8
27
+ connection:
28
+ - keep-alive
29
+ mime-version:
30
+ - "1.0"
31
+ content-length:
32
+ - "73"
33
+ body: "{ \"data\": [ ], \"status_code\": 500, \"status_txt\": \"ALREADY_A_BITLY_LINK\" }"
34
+ http_version: "1.1"
@@ -0,0 +1,36 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: http://api.bit.ly:80/v3/shorten
6
+ body: longURL=http%3A%2F%2Fgoogle.com&login=rafaeldx7&apiKey=R_59c1b174b21d92b2beeb4787a6d7ebaf
7
+ headers:
8
+ accept:
9
+ - "*/*; q=0.5, application/xml"
10
+ accept-encoding:
11
+ - gzip, deflate
12
+ content-length:
13
+ - "89"
14
+ content-type:
15
+ - application/x-www-form-urlencoded
16
+ response: !ruby/struct:VCR::Response
17
+ status: !ruby/struct:VCR::ResponseStatus
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ server:
22
+ - nginx
23
+ date:
24
+ - Sat, 28 May 2011 17:11:14 GMT
25
+ content-type:
26
+ - application/json; charset=utf-8
27
+ connection:
28
+ - keep-alive
29
+ mime-version:
30
+ - "1.0"
31
+ content-length:
32
+ - "184"
33
+ body: |
34
+ { "status_code": 200, "status_txt": "OK", "data": { "long_url": "http:\/\/google.com\/", "url": "http:\/\/bit.ly\/lVW32C", "hash": "lVW32C", "global_hash": "3j4ir4", "new_hash": 0 } }
35
+
36
+ http_version: "1.1"
data/lib/ruby-bitly.rb CHANGED
@@ -1,45 +1,45 @@
1
- require 'rubygems'
1
+ # -*- encoding: utf-8 -*-
2
2
  require 'yaml'
3
3
  require 'restclient'
4
4
  require 'json'
5
5
  require 'ostruct'
6
6
 
7
7
  class Bitly < OpenStruct
8
-
8
+
9
+ VERSION = '0.1.5.beta3'
9
10
  REST_API_URL = "http://api.bit.ly"
10
11
  ACTION_PATH = { :shorten => '/v3/shorten', :expand => '/v3/expand', :clicks => '/v3/clicks' }
11
-
12
+
12
13
  def Bitly.shorten(new_long_url, login, key)
13
14
  response = JSON.parse RestClient.post(REST_API_URL + ACTION_PATH[:shorten], { :longURL => new_long_url, :login => login, :apiKey => key })
14
-
15
+
15
16
  bitly = Bitly.new response["data"]
16
-
17
+
17
18
  bitly.hash_path = response["data"]["hash"] if response["status_code"] == 200
18
19
  bitly.status_code = response["status_code"]
19
20
  bitly.status_txt = response["status_txt"]
20
21
 
21
22
  bitly
22
23
  end
23
-
24
+
24
25
  def Bitly.expand(new_short_url, login, key)
25
26
  response = JSON.parse RestClient.post(REST_API_URL + ACTION_PATH[:expand], { :shortURL => new_short_url, :login => login, :apiKey => key })
26
-
27
+
27
28
  bitly = Bitly.new(response["data"]["expand"].first)
28
29
  bitly.status_code = response["status_code"]
29
30
  bitly.status_txt = response["status_txt"]
30
31
  bitly.long_url = bitly.error if bitly.error
31
-
32
+
32
33
  bitly
33
34
  end
34
-
35
+
35
36
  def Bitly.get_clicks(new_short_url, login, key)
36
37
  response = JSON.parse RestClient.get("#{REST_API_URL}#{ACTION_PATH[:clicks]}?login=#{login}&apiKey=#{key}&shortUrl=#{new_short_url}")
37
- # response = JSON.parse RestClient.get(REST_API_URL + ACTION_PATH[:clicks], { :login => login, :apiKey => key, :shortUrl => new_short_url })
38
38
 
39
39
  bitly = Bitly.new(response["data"]["clicks"].first)
40
40
  bitly.status_code = response["status_code"]
41
41
  bitly.status_txt = response["status_txt"]
42
-
42
+
43
43
  bitly
44
44
  end
45
- end
45
+ end
data/ruby-bitly.gemspec CHANGED
@@ -1,69 +1,22 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ruby-bitly"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{ruby-bitly}
8
- s.version = "0.1.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["rafaeldx7"]
12
- s.date = %q{2010-08-10}
13
- s.default_executable = %q{bitly}
14
- s.description = %q{This is a simple bit.ly ruby client}
15
- s.email = %q{rafaeldx7@gmail.com}
16
- s.executables = ["bitly"]
17
- s.extra_rdoc_files = [
18
- "LICENSE",
19
- "README.rdoc"
20
- ]
21
- s.files = [
22
- ".document",
23
- ".gitignore",
24
- "CHANGELOG",
25
- "LICENSE",
26
- "README.rdoc",
27
- "Rakefile",
28
- "VERSION",
29
- "bin/bitly",
30
- "lib/readme.rb",
31
- "lib/ruby-bitly.rb",
32
- "ruby-bitly.gemspec",
33
- "spec/ruby-bitly_spec.rb",
34
- "spec/spec.opts",
35
- "spec/spec_helper.rb"
36
- ]
37
- s.homepage = %q{http://github.com/rafaeldx7/ruby-bitly}
38
- s.rdoc_options = ["--charset=UTF-8"]
6
+ s.name = "ruby-bitly"
7
+ s.version = Bitly::VERSION
8
+ s.authors = ["rafaeldx7"]
9
+ s.email = ["rafaeldx7@gmail.com"]
10
+ s.homepage = "http://github.com/rafaeldx7/ruby-bitly"
11
+ s.summary = %q{A simple bit.ly ruby client}
12
+ s.description = %q{A simple bit.ly ruby client}
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
39
16
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.3.7}
41
- s.summary = %q{This is a simple bit.ly ruby client}
42
- s.test_files = [
43
- "spec/ruby-bitly_spec.rb",
44
- "spec/spec_helper.rb"
45
- ]
46
-
47
- if s.respond_to? :specification_version then
48
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
- s.specification_version = 3
50
-
51
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
- s.add_runtime_dependency(%q<rest-client>, ["= 1.6.0"])
53
- s.add_runtime_dependency(%q<json_pure>, ["= 1.4.3"])
54
- s.add_development_dependency(%q<rake>, ["= 0.8.7"])
55
- s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
56
- else
57
- s.add_dependency(%q<rest-client>, ["= 1.6.0"])
58
- s.add_dependency(%q<json_pure>, ["= 1.4.3"])
59
- s.add_dependency(%q<rake>, ["= 0.8.7"])
60
- s.add_dependency(%q<rspec>, ["= 1.3.0"])
61
- end
62
- else
63
- s.add_dependency(%q<rest-client>, ["= 1.6.0"])
64
- s.add_dependency(%q<json_pure>, ["= 1.4.3"])
65
- s.add_dependency(%q<rake>, ["= 0.8.7"])
66
- s.add_dependency(%q<rspec>, ["= 1.3.0"])
67
- end
17
+ s.add_dependency('rest-client','~> 1.6.1')
18
+ s.add_development_dependency('rake', '~> 0.8.7')
19
+ s.add_development_dependency('rspec', '~> 2.6.0')
20
+ s.add_development_dependency('vcr', '~> 1.10.0')
21
+ s.add_development_dependency('webmock', '~> 1.6.4')
68
22
  end
69
-
@@ -1,32 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
3
 
3
4
  describe "RubyBitly" do
4
-
5
+
5
6
  before(:all) do
6
7
  @login = 'rafaeldx7'
7
8
  @key = 'R_59c1b174b21d92b2beeb4787a6d7ebaf'
8
9
  end
9
10
 
10
11
  it "Shorten long url" do
11
- response = Bitly.shorten("http://google.com", @login, @key)
12
-
12
+ response = VCR.use_cassette('shorten_long_url') do
13
+ Bitly.shorten("http://google.com", @login, @key)
14
+ end
15
+
13
16
  response.status_code.should == 200
14
17
  response.status_txt.should == "OK"
15
18
  response.new_hash.should == 0
16
- response.global_hash.should == "zzzzzzz"
19
+ response.global_hash.should_not be_empty
17
20
  response.hash_path.length.should_not == 0
18
21
  response.url.should match /^http:\/\/bit\.ly\/[A-Za-z0-9]*/
19
22
  end
20
-
23
+
21
24
  it "Shorten bitly url" do
22
- response = Bitly.shorten("http://bit.ly/bcvNe5", @login, @key)
23
-
25
+ response = VCR.use_cassette('shorten_bitly_url') do
26
+ Bitly.shorten("http://bit.ly/bcvNe5", @login, @key)
27
+ end
28
+
24
29
  response.status_code.should == 500
25
30
  end
26
31
 
27
32
  it "Expand a short url to it long url" do
28
- response = Bitly.expand("http://bit.ly/bcvNe5", @login, @key)
29
-
33
+ response = VCR.use_cassette('expand_a_short_url_to_it_long_url') do
34
+ Bitly.expand("http://bit.ly/bcvNe5", @login, @key)
35
+ end
36
+
30
37
  response.status_code.should == 200
31
38
  response.status_txt.should == "OK"
32
39
  response.long_url.should == "http://google.com"
@@ -35,18 +42,22 @@ describe "RubyBitly" do
35
42
  end
36
43
 
37
44
  it "Expand a long url should result an error" do
38
- response = Bitly.expand("http://google.com", @login, @key)
39
-
45
+ response = VCR.use_cassette('expand_a_long_url_should_result_an_error') do
46
+ Bitly.expand("http://google.com", @login, @key)
47
+ end
48
+
40
49
  response.status_code.should == 200
41
50
  response.status_txt.should == "OK"
42
51
  response.long_url.should == "NOT_FOUND"
43
52
  response.short_url.should == "http://google.com"
44
53
  end
45
54
 
46
-
55
+
47
56
  it "Get clicks by short_url" do
48
- bitly = Bitly.get_clicks("http://bit.ly/xlii42", @login, @key)
49
-
57
+ bitly = VCR.use_cassette('get_clicks_by_short_url') do
58
+ Bitly.get_clicks("http://bit.ly/xlii42", @login, @key)
59
+ end
60
+
50
61
  bitly.status_txt.should == "OK"
51
62
  bitly.status_code.should == 200
52
63
  bitly.global_clicks.should be_an_instance_of Fixnum
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
4
  require 'ruby-bitly'
4
- require 'spec'
5
- require 'spec/autorun'
5
+ require 'rspec'
6
+ require 'rspec/autorun'
7
+ require 'vcr'
6
8
 
7
- Spec::Runner.configure do |config|
8
-
9
+ VCR.config do |c|
10
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
11
+ c.ignore_localhost = true
12
+ c.stub_with :webmock # or :fakeweb
13
+ c.default_cassette_options = { :record => :once }
9
14
  end
metadata CHANGED
@@ -1,145 +1,126 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-bitly
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5.beta3
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - rafaeldx7
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-08-10 00:00:00 -03:00
19
- default_executable: bitly
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-06-11 00:00:00.000000000 -03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rest-client
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2157460620 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - "="
28
- - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 1
32
- - 6
33
- - 0
34
- version: 1.6.0
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.1
35
23
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: json_pure
39
24
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - "="
44
- - !ruby/object:Gem::Version
45
- hash: 1
46
- segments:
47
- - 1
48
- - 4
49
- - 3
50
- version: 1.4.3
51
- type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
25
+ version_requirements: *2157460620
26
+ - !ruby/object:Gem::Dependency
54
27
  name: rake
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
28
+ requirement: &2157459020 !ruby/object:Gem::Requirement
57
29
  none: false
58
- requirements:
59
- - - "="
60
- - !ruby/object:Gem::Version
61
- hash: 49
62
- segments:
63
- - 0
64
- - 8
65
- - 7
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
66
33
  version: 0.8.7
67
34
  type: :development
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
35
+ prerelease: false
36
+ version_requirements: *2157459020
37
+ - !ruby/object:Gem::Dependency
70
38
  name: rspec
39
+ requirement: &2157457440 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 2.6.0
45
+ type: :development
71
46
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *2157457440
48
+ - !ruby/object:Gem::Dependency
49
+ name: vcr
50
+ requirement: &2157445900 !ruby/object:Gem::Requirement
73
51
  none: false
74
- requirements:
75
- - - "="
76
- - !ruby/object:Gem::Version
77
- hash: 27
78
- segments:
79
- - 1
80
- - 3
81
- - 0
82
- version: 1.3.0
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.10.0
83
56
  type: :development
84
- version_requirements: *id004
85
- description: This is a simple bit.ly ruby client
86
- email: rafaeldx7@gmail.com
87
- executables:
57
+ prerelease: false
58
+ version_requirements: *2157445900
59
+ - !ruby/object:Gem::Dependency
60
+ name: webmock
61
+ requirement: &2157443140 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 1.6.4
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2157443140
70
+ description: A simple bit.ly ruby client
71
+ email:
72
+ - rafaeldx7@gmail.com
73
+ executables:
88
74
  - bitly
89
75
  extensions: []
90
-
91
- extra_rdoc_files:
92
- - LICENSE
93
- - README.rdoc
94
- files:
95
- - .document
76
+ extra_rdoc_files: []
77
+ files:
96
78
  - .gitignore
79
+ - .rspec
97
80
  - CHANGELOG
81
+ - Gemfile
82
+ - Gemfile.lock
98
83
  - LICENSE
99
84
  - README.rdoc
100
85
  - Rakefile
101
- - VERSION
102
86
  - bin/bitly
103
- - lib/readme.rb
87
+ - fixtures/vcr_cassettes/expand_a_long_url_should_result_an_error.yml
88
+ - fixtures/vcr_cassettes/expand_a_short_url_to_it_long_url.yml
89
+ - fixtures/vcr_cassettes/get_clicks_by_short_url.yml
90
+ - fixtures/vcr_cassettes/shorten_bitly_url.yml
91
+ - fixtures/vcr_cassettes/shorten_long_url.yml
104
92
  - lib/ruby-bitly.rb
105
93
  - ruby-bitly.gemspec
106
94
  - spec/ruby-bitly_spec.rb
107
- - spec/spec.opts
108
95
  - spec/spec_helper.rb
109
96
  has_rdoc: true
110
97
  homepage: http://github.com/rafaeldx7/ruby-bitly
111
98
  licenses: []
112
-
113
99
  post_install_message:
114
- rdoc_options:
115
- - --charset=UTF-8
116
- require_paths:
100
+ rdoc_options: []
101
+ require_paths:
117
102
  - lib
118
- required_ruby_version: !ruby/object:Gem::Requirement
103
+ required_ruby_version: !ruby/object:Gem::Requirement
119
104
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- hash: 3
124
- segments:
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ segments:
125
110
  - 0
126
- version: "0"
127
- required_rubygems_version: !ruby/object:Gem::Requirement
111
+ hash: -71713400600843204
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
113
  none: false
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- hash: 3
133
- segments:
134
- - 0
135
- version: "0"
114
+ requirements:
115
+ - - ! '>'
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.1
136
118
  requirements: []
137
-
138
119
  rubyforge_project:
139
- rubygems_version: 1.3.7
120
+ rubygems_version: 1.6.2
140
121
  signing_key:
141
122
  specification_version: 3
142
- summary: This is a simple bit.ly ruby client
143
- test_files:
123
+ summary: A simple bit.ly ruby client
124
+ test_files:
144
125
  - spec/ruby-bitly_spec.rb
145
126
  - spec/spec_helper.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.3
data/lib/readme.rb DELETED
@@ -1,137 +0,0 @@
1
- require 'rdoc/markup/simple_markup'
2
- require 'rdoc/markup/simple_markup/to_flow'
3
- require 'rdoc/ri/ri_formatter'
4
- require 'rdoc/ri/ri_options'
5
-
6
- module Readme
7
-
8
- # Display usage information from the comment at the top of
9
- # the file. String arguments identify specific sections of the
10
- # comment to display. An optional integer first argument
11
- # specifies the exit status (defaults to 0)
12
-
13
- def Readme.usage(*args)
14
- exit_code = 0
15
-
16
- if args.size > 0
17
- status = args[0]
18
- if status.respond_to?(:to_int)
19
- exit_code = status.to_int
20
- args.shift
21
- end
22
- end
23
-
24
- # display the usage and exit with the given code
25
- usage_no_exit(*args)
26
- exit(exit_code)
27
- end
28
-
29
- # Display usage
30
- def Readme.usage_no_exit(*args)
31
- # main_program_file = caller[-1].sub(/:\d+$/, '') # ruby-bitly
32
- main_program_file = File.join(File.dirname(__FILE__), '..', 'README.rdoc')
33
-
34
- comment = File.open(main_program_file) do |file|
35
- find_comment(file)
36
- end
37
-
38
- comment = comment.gsub(/^\s*#/, '')
39
-
40
- markup = SM::SimpleMarkup.new
41
- flow_convertor = SM::ToFlow.new
42
-
43
- flow = markup.convert(comment, flow_convertor)
44
-
45
- format = "plain"
46
-
47
- unless args.empty?
48
- flow = extract_sections(flow, args)
49
- end
50
-
51
- options = RI::Options.instance
52
- if args = ENV["RI"]
53
- options.parse(args.split)
54
- end
55
- formatter = options.formatter.new(options, "")
56
- formatter.display_flow(flow)
57
- end
58
-
59
- ######################################################################
60
-
61
- private
62
-
63
- # Find the first comment in the file (that isn't a shebang line)
64
- # If the file doesn't start with a comment, report the fact
65
- # and return empty string
66
-
67
- def Readme.gets(file)
68
- if (line = file.gets) && (line =~ /^#!/) # shebang
69
- throw :exit, find_comment(file)
70
- else
71
- line
72
- end
73
- end
74
-
75
- def Readme.find_comment(file)
76
- catch(:exit) do
77
- # skip leading blank lines
78
- 0 while (line = gets(file)) && (line =~ /^\s*$/)
79
-
80
- comment = []
81
- while line # && line =~ /^\s*#/ # ruby-bitly
82
- comment << line
83
- line = gets(file)
84
- end
85
-
86
- 0 while line && (line = gets(file))
87
- return no_comment if comment.empty?
88
- return comment.join
89
- end
90
- end
91
-
92
-
93
- #####
94
- # Given an array of flow items and an array of section names, extract those
95
- # sections from the flow which have headings corresponding to
96
- # a section name in the list. Return them in the order
97
- # of names in the +sections+ array.
98
-
99
- def Readme.extract_sections(flow, sections)
100
- result = []
101
- sections.each do |name|
102
- name = name.downcase
103
- copy_upto_level = nil
104
-
105
- flow.each do |item|
106
- case item
107
- when SM::Flow::H
108
- if copy_upto_level && item.level >= copy_upto_level
109
- copy_upto_level = nil
110
- else
111
- if item.text.downcase == name
112
- result << item
113
- copy_upto_level = item.level
114
- end
115
- end
116
- else
117
- if copy_upto_level
118
- result << item
119
- end
120
- end
121
- end
122
- end
123
-
124
- if result.empty?
125
- # puts "Note to developer: requested section(s) [#{sections.join(', ')}] not found"
126
- result = flow
127
- end
128
- result
129
- end
130
-
131
- #####
132
- # Report the fact that no doc comment count be found
133
- def Readme.no_comment
134
- $stderr.puts "No usage information available for this program"
135
- ""
136
- end
137
- end