ruby-bitly 0.2.1 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d1771cca1a80ce56b33cfb9578d3bd378f0ce83c
4
- data.tar.gz: c0fffae72cbab2491b2bb4a5688f192b6d48af00
2
+ SHA256:
3
+ metadata.gz: bc2319a77b8e27a1232ec307d0340da712918cc5a1e7debbd0de2c4bc48c24b5
4
+ data.tar.gz: 35f06c843599ba7176f1509475633357720b324b1eddb4f411b8740f531bde85
5
5
  SHA512:
6
- metadata.gz: ed38e9827405f2463b37377ed955801c8f4be6173f418e83b777feacc4f123f150f8cad56f0f0cdbe2f30af80bf7ef33106586bdea31cac9fc8dc49a66f6e616
7
- data.tar.gz: 9d3ecf027d2a2bf44786337415ce1ae88e565b00507c037d5787a3092d64bb4f81045ecf431446b7b8063ab75f9d8a81ffd0bfe60e44be09918dfb129e467f08
6
+ metadata.gz: dab564991fac44286a064b29be9b83d0a9ab1e28c25e3ee6fa9710b54acefd599615dc03a49764eb57d9c9882fb5f3ab70a48ad11657032e6363d70d24b2bf51
7
+ data.tar.gz: 5942d8c6baeda9d0301d48955f08a93ec082a8937449c726bd01ddc2f995299e40094359c019fe408df5c1fbe09564be970a0c5d73513ae0ac3774e289b66aac
@@ -1,7 +1,17 @@
1
1
  language: ruby
2
+ before_install:
3
+ - gem install rubygems-update -v '<3' && update_rubygems
4
+ gemfile:
5
+ - gemfiles/rest-client-2.1.0.rc1.gemfile
6
+ - gemfiles/rest-client-2.0.2.gemfile
7
+ - gemfiles/rest-client-2.0.1.gemfile
8
+ script:
9
+ - bundle exec rake spec
2
10
  rvm:
3
- - 2.0.0
11
+ - 2.6.3
12
+ - 2.5.5
13
+ - 2.4.6
14
+ - 2.3.8
15
+ - 2.2.10
4
16
  - 2.1.10
5
- - 2.2.5
6
- - 2.3.1
7
- - 2.4.0
17
+ - 2.0.0
data/CHANGELOG CHANGED
@@ -1,4 +1,15 @@
1
+ # 3.0.0.rc1 - BREAKING CHANGES!
2
+
3
+ - Update README with all updates and breaking changes. Check it out!
4
+ - Remove the first zero when bumping version: 0.2.1 => 3.0.0
5
+ - Remove deprecated API
6
+ - Rename method `hash_path` to `user_hash`
7
+ - Rename boolean method `new_hash` to `new_hash?`
8
+ - Add attributes `success?` and `error?` to better error handling
9
+ - Remove old attributes `status_code` and `status_txt`
10
+
1
11
  # 0.2.1
12
+
2
13
  - Add support for ruby 2.4.0
3
14
  - Add support for set domain on command line
4
15
  - Remove feature 'copy to clipboard' on command line
@@ -7,15 +7,14 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.5.0)
11
- public_suffix (~> 2.0, >= 2.0.2)
12
- byebug (9.0.6)
10
+ addressable (2.6.0)
11
+ public_suffix (>= 2.0.2, < 4.0)
13
12
  crack (0.4.3)
14
13
  safe_yaml (~> 1.0.0)
15
14
  diff-lcs (1.3)
16
15
  domain_name (0.5.20170223)
17
16
  unf (>= 0.0.5, < 1.0.0)
18
- hashdiff (0.3.2)
17
+ hashdiff (0.3.9)
19
18
  http-cookie (1.0.3)
20
19
  domain_name (~> 0.5)
21
20
  mime-types (3.1)
@@ -23,44 +22,46 @@ GEM
23
22
  mime-types-data (3.2016.0521)
24
23
  netrc (0.11.0)
25
24
  public_suffix (2.0.5)
26
- rake (12.0.0)
25
+ rake (12.3.2)
27
26
  rest-client (2.0.1)
28
27
  http-cookie (>= 1.0.2, < 2.0)
29
28
  mime-types (>= 1.16, < 4.0)
30
29
  netrc (~> 0.8)
31
- rspec (3.5.0)
32
- rspec-core (~> 3.5.0)
33
- rspec-expectations (~> 3.5.0)
34
- rspec-mocks (~> 3.5.0)
35
- rspec-core (3.5.4)
36
- rspec-support (~> 3.5.0)
37
- rspec-expectations (3.5.0)
30
+ rspec (3.8.0)
31
+ rspec-core (~> 3.8.0)
32
+ rspec-expectations (~> 3.8.0)
33
+ rspec-mocks (~> 3.8.0)
34
+ rspec-core (3.8.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-expectations (3.8.3)
38
37
  diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.5.0)
40
- rspec-mocks (3.5.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-mocks (3.8.0)
41
40
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.5.0)
43
- rspec-support (3.5.0)
44
- safe_yaml (1.0.4)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-support (3.8.0)
43
+ safe_yaml (1.0.5)
45
44
  unf (0.1.4)
46
45
  unf_ext
47
46
  unf_ext (0.0.7.2)
48
- vcr (3.0.3)
49
- webmock (2.3.2)
47
+ vcr (4.0.0)
48
+ webmock (3.5.1)
50
49
  addressable (>= 2.3.6)
51
50
  crack (>= 0.3.2)
52
51
  hashdiff
52
+ wwtd (1.3.0)
53
53
 
54
54
  PLATFORMS
55
55
  ruby
56
56
 
57
57
  DEPENDENCIES
58
- byebug
58
+ public_suffix (< 3)
59
59
  rake
60
- rspec (~> 3.5)
60
+ rspec
61
61
  ruby-bitly!
62
- vcr (~> 3.0)
63
- webmock (~> 2.1)
62
+ vcr
63
+ webmock
64
+ wwtd
64
65
 
65
66
  BUNDLED WITH
66
- 1.14.6
67
+ 1.17.3
@@ -13,8 +13,7 @@
13
13
 
14
14
  Bitly.config do |c|
15
15
  c.login = 'login-here'
16
- c.api_key = 'key-here'
17
- c.key = 'key-here' # deprecated: use api_key instead
16
+ c.api_key = 'api-key-here'
18
17
  c.use_ssl = false # read more below
19
18
  c.proxy = 'http://localhost:8888' # read more below
20
19
  end
@@ -22,8 +21,7 @@
22
21
  Or set them individualy:
23
22
 
24
23
  Bitly.login = 'login-here'
25
- Bitly.api_key = 'key-here'
26
- Bitly.key = 'key-here' # deprecated: use api_key instead
24
+ Bitly.api_key = 'api-key-here'
27
25
  Bitly.use_ssl = false # read more below
28
26
  Bitly.proxy = 'http://localhost:8888' # read more below
29
27
 
@@ -31,77 +29,54 @@
31
29
 
32
30
 
33
31
  == Shorten
34
- # old way
35
- bitly = Bitly.shorten("https://dx7.github.io/")
32
+ bitly = Bitly.shorten(long_url: "https://dx7.github.io/")
36
33
 
37
- # old way setting local configuration
38
- bitly = Bitly.shorten("https://dx7.github.io/", "login-here", "key-here")
39
-
40
- # new way
41
- bitly = Bitly.shorten(url: "https://dx7.github.io/")
42
-
43
- # new way setting local configuration
44
- bitly = Bitly.shorten(url: "https://dx7.github.io/", login: "login-here", api_key: "key-here", domain: "my.do")
34
+ # setting credentials
35
+ bitly = Bitly.shorten(long_url: "https://dx7.github.io/", domain: "my.do", login: "login-here", api_key: "api-key-here")
45
36
 
46
37
  # result
47
- bitly.url #=> "http://bit.ly/2dAjjfo"
48
-
49
- y bitly
50
- :long_url: http://dx7.github.io/
51
- :url: http://bit.ly/2dAjjfo
52
- :hash: 2dAjjfo
53
- :global_hash: micSj7
54
- :new_hash: 0
55
- :hash_path: 2dAjjfo
56
- :status_code: 200
57
- :status_txt: OK
38
+ bitly.short_url #=> "http://bit.ly/2dAjjfo"
39
+ bitly.long_url #=> "https://dx7.github.io/"
40
+ bitly.new_hash? #=> true
41
+ bitly.global_hash #=> "2dAkyet"
42
+ bitly.user_hash #=> "2dAjjfo"
43
+ bitly.success? #=> true
58
44
 
59
45
 
60
46
  == Expand
61
- # old way
62
- bitly = Bitly.expand("http://bit.ly/2dAjjfo")
63
-
64
- # old way setting local configuration
65
- bitly = Bitly.expand("http://bit.ly/2dAjjfo", "login-here", "key-here")
47
+ bitly = Bitly.expand(short_url: "http://bit.ly/2dAjjfo")
66
48
 
67
- # new way
68
- bitly = Bitly.expand(url: "http://bit.ly/2dAjjfo")
69
-
70
- # new way setting local configuration
71
- bitly = Bitly.expand(url: "http://bit.ly/2dAjjfo", login: "login-here", api_key: "key-here")
49
+ # setting credentials
50
+ bitly = Bitly.expand(short_url: "http://bit.ly/2dAjjfo", login: "login-here", api_key: "api-key-here")
72
51
 
73
52
  # result
74
- y bitly
75
- :short_url: http://bit.ly/2dAjjfo
76
- :long_url: https://dx7.github.io/
77
- :user_hash: 2dAjjfo
78
- :global_hash: 2dAkyet
79
- :status_code: 200
80
- :status_txt: OK
53
+ bitly.short_url #=> "http://bit.ly/2dAjjfo"
54
+ bitly.long_url #=> "https://dx7.github.io/"
55
+ bitly.global_hash #=> "2dAkyet"
56
+ bitly.user_hash #=> "2dAjjfo"
57
+ bitly.success? #=> true
81
58
 
82
59
 
83
60
  == Get Clicks
84
- # old way
85
- bitly = Bitly.get_clicks("http://bit.ly/2dAjjfo")
61
+ bitly = Bitly.get_clicks(short_url: "http://bit.ly/2dAjjfo")
62
+
63
+ # setting credentials
64
+ bitly = Bitly.get_clicks(short_url: "http://bit.ly/2dAjjfo", login: "login-here", api_key: "api-key-here")
86
65
 
87
- # old way setting local configuration
88
- bitly = Bitly.get_clicks("http://bit.ly/2dAjjfo", "login-here", "key-here")
66
+ # result
67
+ bitly.short_url #=> "http://bit.ly/2dAjjfo"
68
+ bitly.user_hash #=> "2dAjjfo"
69
+ bitly.global_hash #=> "2dAkyet"
70
+ bitly.user_clicks #=> 0
71
+ bitly.global_clicks #=> 1
72
+ bitly.success? #=> true
89
73
 
90
- # new way
91
- bitly = Bitly.get_clicks(url: "http://bit.ly/2dAjjfo")
92
74
 
93
- # new way setting local configuration
94
- bitly = Bitly.get_clicks(url: "http://bit.ly/2dAjjfo", login: "login-here", api_key: "key-here")
75
+ == Error handling
95
76
 
96
- # result
97
- y bitly
98
- :short_url: https://bit.ly/2dAjjfo
99
- :global_hash: 2dAkyet
100
- :user_clicks: 0
101
- :user_hash: 2dAjjfo
102
- :global_clicks: 0
103
- :status_code: 200
104
- :status_txt: OK
77
+ # if something goes wrong you can check
78
+ bitly.success? #=> false
79
+ bitly.error #=> 'INVALID_LOGIN'
105
80
 
106
81
 
107
82
  == Proxy
@@ -119,10 +94,20 @@
119
94
 
120
95
 
121
96
  == Command Line
122
- Usage
123
- bitly [options] url
97
+ Usage: bitly [options] URL
98
+ -l, --login LOGIN You need a free Bitly login and api key. Sign up here: http://bit.ly/a/sign_up.
99
+ -k, --api-key KEY You can find your api key here: http://bit.ly/a/your_api_key.
124
100
 
125
- For help: bitly -h
101
+ -d, --domain DOMAIN The short domain to use: either bit.ly, j.mp, bitly.com or a custom short domain.
102
+ This option will override the default short domain selected in your Bitly account settings.
103
+
104
+ -s, --shorten Given a long URL, returns a Bitlink.
105
+ -e, --expand Given a Bitlink, hash or custom path, returns the target (long) URL.
106
+ -u, --user-clicks The total count of clicks to this user's Bitlink.
107
+ -g, --global-clicks The total count of the corresponding Bitly aggregate hash.
108
+
109
+ -h, --help Print this help.
110
+ -v, --version Print version.
126
111
 
127
112
  Basic examples:
128
113
  bitly -s http://dx7.github.io
@@ -130,37 +115,16 @@
130
115
  bitly --user-clicks http://bit.ly/2dAjjfo
131
116
  bitly --global-clicks http://bit.ly/2dAjjfo
132
117
 
133
- Other examples:
134
- bitly -q -s http://dx7.github.io
135
- bitly --verbose -e http://bit.ly/2dAjjfo
136
-
137
- Options
138
- -s, --shorten Shorten a long url (default option)
139
- -e, --expand Expand a short bitly url
140
- -u, --user-clicks Show user clicks from the short bitly url
141
- -g, --global-clicks Show global clicks from the short bitly url
142
-
143
- -l, --login LOGIN Your bit.ly login
144
- -k, --key KEY Your bit.ly API key
145
-
146
- -h, --help Displays help message, then exit
147
- -v, --version Display the version, then exit
148
- -q, --quiet Output as little as possible, overrides verbose
149
- -V, --verbose Verbose output
150
-
151
118
 
152
119
  == Authentication
153
120
  bit.ly API requires authentication credentials.
154
121
 
155
- You'll need a free bit.ly login and apiKey. Sign up here: http://bit.ly/a/sign_up
156
- If you've already signed up, you can find your apiKey here: http://bit.ly/a/your_api_key
157
-
158
122
  Using commmand line you can supply credentials as parameters. For example:
159
- bitly -l <login-here> -k <key-here> -s http://dx7.github.io
123
+ bitly -l <login-here> -k <api-key-here> -s http://dx7.github.io
160
124
 
161
125
  Or you can create the file ~/.bitly (YAML format) with that content:
162
126
  login: <login-here>
163
- key: <key-here>
127
+ api_key: <api-key-here>
164
128
 
165
129
 
166
130
  == Author
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
+ require 'wwtd/tasks'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
- task :default => :spec
7
+ task :default => 'wwtd:local'
data/bin/bitly CHANGED
@@ -13,106 +13,52 @@ class App
13
13
 
14
14
  attr_accessor :arguments, :options
15
15
 
16
- def initialize(arguments, stdin = nil)
17
- self.options = OpenStruct.new
16
+ def initialize(arguments)
18
17
  self.arguments = arguments
19
- @stdin = stdin
18
+ self.options = OpenStruct.new
20
19
  end
21
20
 
22
21
  def run
22
+ load_account_data
23
23
  process_options
24
-
25
- if arguments_valid?
26
- output_options if options.verbose
27
-
28
- post_process_options and process_arguments
29
-
30
- result = process_command
31
-
32
- puts "#{options.message} #{result}".strip
33
- else
34
- output_help("ERROR: Invalid options", 'examples')
35
- end
24
+ puts process_command
36
25
  end
37
26
 
38
27
  protected
39
28
 
40
29
  def load_account_data
41
- begin
42
- account_data = YAML.load(File.read(ACCOUNT_FILE_PATH))
43
- rescue
44
- output_help("ERROR: Crendentials not found", 'authentication')
45
- end
46
-
47
- if account_data
48
- options.login = account_data["login"]
49
- options.key = account_data["key"]
50
- end
51
- end
52
-
53
- def default_options
54
- options.verbose = false
55
- options.quiet = false
30
+ account_data = YAML.load(File.read(ACCOUNT_FILE_PATH)) rescue {}
31
+ options.login = account_data['login']
32
+ options.api_key = account_data['api_key']
33
+ rescue
56
34
  end
57
35
 
58
36
  def process_options
59
- default_options
60
-
61
- opts = OptionParser.new
62
-
63
- opts.on('-s', '--shorten') { options.shorten = true; options.message = 'Short url:' }
64
- opts.on('-e', '--expand') { options.expand = true; options.message = 'Original url:' }
65
- opts.on('-u', '--user-clicks') { options.user_clicks = true; options.message = 'User clicks:' }
66
- opts.on('-g', '--global-clicks') { options.global_clicks = true; options.message = 'Global clicks:' }
67
-
68
- opts.on('-l', '--login LOGIN') { |login| options.login = login }
69
- opts.on('-k', '--key KEY') { |key| options.key = key }
70
- opts.on('-d', '--domain DOMAIN') { |domain| options.domain = domain }
71
-
72
- opts.on('-v', '--version') { output_version ; exit 0 }
73
- opts.on('-h', '--help') { output_help }
74
- opts.on('-V', '--verbose') { options.verbose = true }
75
- opts.on('-q', '--quiet') { options.quiet = true; options.verbose = false }
76
-
77
- opts.parse!(arguments) rescue return false
78
- end
79
-
80
- def post_process_options
81
- # Bitly API Login / Key
82
- load_account_data unless options.login and options.key
83
-
84
- # Default option: --shorten
85
- options.shorten = true and options.message = 'Short url:' unless options.expand or options.user_clicks or options.global_clicks
86
-
87
- # Message empty if option quiet exists
88
- options.message = '' if options.quiet
89
- end
37
+ OptionParser.new do |opts|
38
+ opts.banner = "Usage: bitly [options] URL"
90
39
 
91
- def output_options
92
- puts "Options:\n"
93
-
94
- options.marshal_dump.each do |name, val|
95
- puts " #{name} = #{val}"
96
- end
97
-
98
- puts " URL: #{arguments.first}\n"
99
- end
40
+ opts.on('-l', '--login LOGIN', 'You need a free Bitly login and api key. Sign up here: http://bit.ly/a/sign_up.') do |login|
41
+ options.login = login
42
+ end
100
43
 
101
- def arguments_valid?
102
- arguments.length == 1
103
- end
44
+ opts.on('-k', '--api-key KEY', 'You can find your api key here: http://bit.ly/a/your_api_key.', ' ') do |api_key|
45
+ options.api_key = api_key
46
+ end
104
47
 
105
- def process_arguments
106
- end
48
+ opts.on('-d', '--domain DOMAIN',
49
+ 'The short domain to use: either bit.ly, j.mp, bitly.com or a custom short domain.',
50
+ 'This option will override the default short domain selected in your Bitly account settings.', ' ') do |domain|
51
+ options.domain = domain
52
+ end
107
53
 
108
- def output_help(message = nil, section = "")
109
- puts message if message
54
+ opts.on('-s', '--shorten', 'Given a long URL, returns a Bitlink.') { options.command = :shorten }
55
+ opts.on('-e', '--expand', 'Given a Bitlink, hash or custom path, returns the target (long) URL.') { options.command = :expand }
56
+ opts.on('-u', '--user-clicks', 'The total count of clicks to this user\'s Bitlink.') { options.command = :user_clicks }
57
+ opts.on('-g', '--global-clicks', 'The total count of the corresponding Bitly aggregate hash.', ' ') { options.command = :global_clicks }
110
58
 
111
- File.open(File.join(File.dirname(__FILE__), '..', 'README.rdoc'), "r") do |infile|
112
- while (line = infile.gets)
113
- puts line
114
- end
115
- end
59
+ opts.on('-h', '--help', 'Print this help.') { puts opts.help; exit 0 }
60
+ opts.on('-v', '--version', 'Print version.') { output_version; exit 0 }
61
+ end.parse!
116
62
  end
117
63
 
118
64
  def output_version
@@ -120,13 +66,19 @@ class App
120
66
  end
121
67
 
122
68
  def process_command
123
- return Bitly.shorten(url: arguments.first, login: options.login, api_key: options.key, domain: options.domain).url if options.shorten && options.domain
124
- return Bitly.shorten(url: arguments.first, login: options.login, api_key: options.key).url if options.shorten
125
- return Bitly.expand(url: arguments.first, login: options.login, api_key: options.key).long_url if options.expand
126
- return Bitly.get_clicks(url: arguments.first, login: options.login, api_key: options.key).user_clicks.to_s if options.user_clicks
127
- return Bitly.get_clicks(url: arguments.first, login: options.login, api_key: options.key).global_clicks.to_s if options.global_clicks
69
+ case options.command
70
+ when :shorten
71
+ Bitly.shorten(long_url: arguments.first, login: options.login, api_key: options.api_key, domain: options.domain).short_url
72
+ when :expand
73
+ Bitly.expand(short_url: arguments.first, login: options.login, api_key: options.api_key).long_url
74
+ when :user_clicks
75
+ Bitly.get_clicks(short_url: arguments.first, login: options.login, api_key: options.api_key).user_clicks.to_s
76
+ when :global_clicks
77
+ Bitly.get_clicks(short_url: arguments.first, login: options.login, api_key: options.api_key).global_clicks.to_s
78
+ else
79
+ "No command given"
80
+ end
128
81
  end
129
82
  end
130
83
 
131
- app = App.new(ARGV)
132
- app.run
84
+ App.new(ARGV).run