bitlyr 0.9.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.
Files changed (95) hide show
  1. data/History.txt +146 -0
  2. data/LICENSE +20 -0
  3. data/README.md +97 -0
  4. data/README.rdoc +37 -0
  5. data/Rakefile +43 -0
  6. data/VERSION +1 -0
  7. data/bitlyr.gemspec +154 -0
  8. data/lib/bitlyr/client.rb +153 -0
  9. data/lib/bitlyr/country.rb +10 -0
  10. data/lib/bitlyr/day.rb +12 -0
  11. data/lib/bitlyr/error.rb +13 -0
  12. data/lib/bitlyr/lib/core_ext/hash.rb +27 -0
  13. data/lib/bitlyr/lib/core_ext/string.rb +5 -0
  14. data/lib/bitlyr/missing_url.rb +12 -0
  15. data/lib/bitlyr/realtime_link.rb +16 -0
  16. data/lib/bitlyr/referrer.rb +12 -0
  17. data/lib/bitlyr/response.rb +39 -0
  18. data/lib/bitlyr/strategy/access_token.rb +26 -0
  19. data/lib/bitlyr/strategy/api_key.rb +33 -0
  20. data/lib/bitlyr/strategy/base.rb +26 -0
  21. data/lib/bitlyr/strategy/oauth.rb +50 -0
  22. data/lib/bitlyr/url.rb +124 -0
  23. data/lib/bitlyr/user.rb +100 -0
  24. data/lib/bitlyr.rb +39 -0
  25. data/test/fixtures/9uX1TE.json +1 -0
  26. data/test/fixtures/9uX1TEclicks.json +1 -0
  27. data/test/fixtures/9uX1TEclicks2.json +1 -0
  28. data/test/fixtures/9uX1TEinfo.json +1 -0
  29. data/test/fixtures/9uX1TEinfo2.json +1 -0
  30. data/test/fixtures/auth_fail.json +1 -0
  31. data/test/fixtures/auth_success.json +1 -0
  32. data/test/fixtures/betaworks.json +1 -0
  33. data/test/fixtures/betaworks2.json +1 -0
  34. data/test/fixtures/betaworks_jmp.json +1 -0
  35. data/test/fixtures/betaworks_other_user.json +1 -0
  36. data/test/fixtures/bitly9uX1TE.json +1 -0
  37. data/test/fixtures/bitly_pro_domain.json +1 -0
  38. data/test/fixtures/clicks_by_day.json +1 -0
  39. data/test/fixtures/clicks_by_day1.json +1 -0
  40. data/test/fixtures/clicks_by_day2.json +1 -0
  41. data/test/fixtures/clicks_by_minute1_url.json +1 -0
  42. data/test/fixtures/clicks_by_minute2_url.json +1 -0
  43. data/test/fixtures/clicks_by_minute_hash.json +1 -0
  44. data/test/fixtures/clicks_by_minute_hashes.json +1 -0
  45. data/test/fixtures/country_hash.json +1 -0
  46. data/test/fixtures/country_hash2.json +1 -0
  47. data/test/fixtures/country_url.json +1 -0
  48. data/test/fixtures/failure.json +1 -0
  49. data/test/fixtures/invalid_bitly_pro_domain.json +1 -0
  50. data/test/fixtures/invalid_credentials.json +1 -0
  51. data/test/fixtures/invalid_domain.json +1 -0
  52. data/test/fixtures/invalid_user.json +1 -0
  53. data/test/fixtures/invalid_x_api_key.json +1 -0
  54. data/test/fixtures/lookup_multiple_url.json +1 -0
  55. data/test/fixtures/lookup_not_real_url.json +1 -0
  56. data/test/fixtures/lookup_single_url.json +1 -0
  57. data/test/fixtures/missing_hash.json +1 -0
  58. data/test/fixtures/multiple_info.json +1 -0
  59. data/test/fixtures/multiple_url_click.json +1 -0
  60. data/test/fixtures/multiple_urls.json +1 -0
  61. data/test/fixtures/not_bitly_pro_domain.json +1 -0
  62. data/test/fixtures/not_found_info.json +1 -0
  63. data/test/fixtures/referrer_hash.json +1 -0
  64. data/test/fixtures/referrer_hash2.json +1 -0
  65. data/test/fixtures/referrer_url.json +1 -0
  66. data/test/fixtures/success.json +1 -0
  67. data/test/fixtures/url_info.json +1 -0
  68. data/test/fixtures/user_clicks.json +32 -0
  69. data/test/fixtures/user_countries.json +60 -0
  70. data/test/fixtures/user_realtime_links.json +15 -0
  71. data/test/fixtures/user_referrers.json +1 -0
  72. data/test/fixtures/valid_user.json +1 -0
  73. data/test/integration/strategy/test_api_key.rb +20 -0
  74. data/test/integration/strategy/test_oauth.rb +52 -0
  75. data/test/integration/test_client.rb +1415 -0
  76. data/test/integration/test_user.rb +97 -0
  77. data/test/test_helper.rb +54 -0
  78. data/test/unit/core_ext/test_hash.rb +69 -0
  79. data/test/unit/core_ext/test_string.rb +14 -0
  80. data/test/unit/strategy/test_access_token.rb +14 -0
  81. data/test/unit/strategy/test_api_key.rb +11 -0
  82. data/test/unit/strategy/test_base.rb +71 -0
  83. data/test/unit/strategy/test_oauth.rb +32 -0
  84. data/test/unit/test_bitly.rb +43 -0
  85. data/test/unit/test_client.rb +21 -0
  86. data/test/unit/test_country.rb +20 -0
  87. data/test/unit/test_day.rb +22 -0
  88. data/test/unit/test_error.rb +11 -0
  89. data/test/unit/test_missing.rb +34 -0
  90. data/test/unit/test_realtime_link.rb +30 -0
  91. data/test/unit/test_referrer.rb +20 -0
  92. data/test/unit/test_response.rb +86 -0
  93. data/test/unit/test_url.rb +155 -0
  94. data/test/unit/test_user.rb +17 -0
  95. metadata +233 -0
data/History.txt ADDED
@@ -0,0 +1,146 @@
1
+ === 0.8.0 / 2012-1-17
2
+
3
+ * Major Refactor
4
+
5
+ * Adds Authentication Strategies
6
+ * Client supports OAuth & Login/ApiKey strategies
7
+ * User supports AccessToken strategy
8
+ * Forked original project. Pull requests in original project showed no movement.
9
+
10
+ === 0.7.0 / 2011-1-8
11
+
12
+ * 1 major bug fix
13
+
14
+ * Updates OAuth2 gem and fixes OAuth class
15
+
16
+ * 1 minor enhancement
17
+
18
+ Adds link_history to user model
19
+
20
+ === 0.6.2 / 2011-11-10
21
+
22
+ * 2 minor enhancements
23
+
24
+ * Adds days parameter to clicks_by_minute v3 API call
25
+ * Converts Readme to markdown
26
+
27
+ * 2 minor bug fixes
28
+
29
+ * Increases HTTParty version to avoid issues with Rubygems
30
+ * Stops mutating arguments on array methods
31
+
32
+ === 0.6.1 / 2011-01-12
33
+
34
+ * 1 minor enhancement
35
+
36
+ * Updated OAuth2 gem and used extra information to save login and api_key to user objects
37
+
38
+ === 0.6.0 / 2011-01-03
39
+
40
+ * 1 major enhancement
41
+
42
+ * Added OAuth 2 and User calls for the version 3 API
43
+
44
+ === 0.5.5 / 2010-12-22
45
+
46
+ * 1 minor bug fix
47
+
48
+ * fixed method redifined warnings
49
+
50
+ === 0.5.4 / 2010-12-01
51
+
52
+ * 4 minor enhancements
53
+
54
+ * Added referrers, countries, clicks_by_minute and clicks_by_day calls to the version 3 API
55
+
56
+ === 0.5.3 / 2010-07-30
57
+
58
+ * 1 minor enhancement
59
+
60
+ * Added the info call to the version 3 API
61
+
62
+ === 0.5.2 / 2010-07-18
63
+
64
+ * 1 minor enhancement
65
+
66
+ * Added the lookup call to the version 3 API.
67
+
68
+ === 0.5.1 / 2010-05-26
69
+
70
+ * 1 bug fix
71
+
72
+ * When expanding a short url with the v3 module, user hash and short url weren't being set properly
73
+
74
+ === 0.5.0 / 2010-05-12
75
+
76
+ * Loads of major enhancements
77
+
78
+ * Support for version 3 of the bit.ly API
79
+ * deprecation for version 2 client object
80
+
81
+ === 0.4.0 / 2009-12-19
82
+
83
+ * 1 major enhancement
84
+
85
+ * support for j.mp urls
86
+
87
+ === 0.3.2 / 2009-11-15
88
+
89
+ * 1 bug fix
90
+
91
+ * called the wrong variable in case of error in the creation of a Url object
92
+
93
+ === 0.3.1 / 2009-07-29
94
+
95
+ * 1 minor enhancement
96
+
97
+ * removed require 'rubygems' from library (http://gist.github.com/54177)
98
+
99
+ === 0.3 / 2009-07-09
100
+
101
+ * 1 major enhancement
102
+
103
+ * a full set of tests, properly mocked
104
+
105
+ * 1 minor enhancement
106
+
107
+ * calling bitly.shorten(:history => 1) will add the url to the api user's history.
108
+
109
+ * 1 bug fix
110
+
111
+ * you can no longer call shorten with a keyword, this was unsupported in the API and consequently removed
112
+
113
+ === 0.2 / 2009-06-23
114
+
115
+ * 1 enhancement
116
+
117
+ * Depends on Crack instead of JSON, so can run on Jruby
118
+
119
+ * 1 bug fix
120
+
121
+ * Does not choke when bit.ly chokes. Returns a BitlyError instead
122
+
123
+ === 0.1.4 / 2009-04-13
124
+
125
+ * 1 bug fix
126
+
127
+ * Urls with parameters were choking, changed to using CGI.
128
+
129
+ === 0.1.2 / 2009-03-12
130
+
131
+ * 1 minor enhancement
132
+
133
+ * Allows to add a keyword for shortening urls
134
+
135
+ === 0.1.1 / 2009-01-26
136
+
137
+ * 1 bug fix
138
+
139
+ * Didn't include dependency on JSON
140
+
141
+ === 0.1.0 / 2009-01-26
142
+
143
+ * 1 major enhancement
144
+
145
+ * First release
146
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 philnash
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # bitlyr
2
+
3
+ ## DESCRIPTION:
4
+
5
+ A Ruby API for [http://bit.ly](http://bit.ly)
6
+
7
+ [http://code.google.com/p/bitly-api/wiki/ApiDocumentation](http://code.google.com/p/bitly-api/wiki/ApiDocumentation)
8
+
9
+ ## NOTE:
10
+
11
+ Bitly recently released their version 3 API. From this 0.9.0 release, the gem with only use the version 3 API.
12
+
13
+ The gem will continue to support both Username and ApiKey as well as the OAuth Client ID and Client Secret
14
+
15
+ To use, you will need to select a authorization strategy:
16
+
17
+ strategy = Bitlyr::Strategy::ApiKey.new(username, api_key)
18
+
19
+ or
20
+
21
+ strategy = Bitlyr::Strategy::OAuth.new(client_id, client_secret)
22
+
23
+ Once you have a strategy, you can initialize your client:
24
+
25
+ client = Bitlyr::Client.new(strategy)
26
+
27
+ which will give you a ``Bitlyr::Client`` which provides access to the version 3 endpoints (``shorten``, ``expand``, ``clicks``, ``validate`` and ``bitly_pro_domain``). See [http://api.bit.ly](http://api.bit.ly) for details.
28
+
29
+
30
+ ## INSTALLATION:
31
+
32
+ gem install bitlyr
33
+
34
+ ## USAGE:
35
+
36
+ Please see the Bit.ly API documentation [http://api.bit.ly](http://api.bit.ly) for details on the V3 API.
37
+
38
+ Create a Bitlyr client using your username and api key as follows:
39
+
40
+ client = Bitlyr.new(:login => "login", :api_key => "api_key")
41
+
42
+ or
43
+
44
+ client = Bitlyr.new(:client_id => "client id", :client_secret => "client secret", :token => "token")
45
+
46
+ You can then use that client to shorten or expand urls or return more information or statistics as so:
47
+
48
+ client.shorten('http://www.google.com')
49
+ client.shorten('http://www.google.com', :history => 1) # adds the url to the api user's history
50
+ client.expand('wQaT') || client.expand('http://bit.ly/wQaT')
51
+ client.info('wQaT') || client.info('http://bit.ly/wQaT')
52
+ client.stats('wQaT') || client.info('http://bit.ly/wQaT')
53
+
54
+ Each can be used in all the methods described in the API docs, the shorten function, for example, takes a url or an array of urls.
55
+
56
+ All four functions return a ``Bitlyr::Url`` object (or an array of ``Bitlyr::Url`` objects if you supplied an array as the input). You can then get all the information required from that object.
57
+
58
+ url = client.shorten('http://www.google.com') #=> Bitlyr::Url
59
+
60
+ url.clicks_by_day #=> an array of ``Bitlyr::Day``s
61
+ url.countries #=> an array of ``Bitlyr::Country``s
62
+ url.referrers #=> an array of ``Bitlyr::Referrer``s
63
+ url.clicks_by_minute #=> an array of 60 integers representing clicks over the last 60 minutes
64
+ url.created_by #=> string / http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/info
65
+ url.global_clicks #=> integer / http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/clicks
66
+ url.global_hash #=> string / http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/info
67
+ url.long_url #=> string / http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/expand
68
+ url.new_hash? #=> boolean / http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/shorten
69
+ url.short_url #=> string / http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/shorten
70
+ url.title #=> string / http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/info
71
+ url.user_clicks #=> integer / http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/clicks
72
+ url.user_hash #=> string / http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/expand
73
+
74
+ ## LICENSE:
75
+
76
+ > (The MIT License)
77
+ >
78
+ > Copyright (c) 2012 Jonathon Storer
79
+ >
80
+ > Permission is hereby granted, free of charge, to any person obtaining
81
+ > a copy of this software and associated documentation files (the
82
+ > 'Software'), to deal in the Software without restriction, including
83
+ > without limitation the rights to use, copy, modify, merge, publish,
84
+ > distribute, sublicense, and/or sell copies of the Software, and to
85
+ > permit persons to whom the Software is furnished to do so, subject to
86
+ > the following conditions:
87
+ >
88
+ > The above copyright notice and this permission notice shall be
89
+ > included in all copies or substantial portions of the Software.
90
+ >
91
+ > THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
92
+ > EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
93
+ > MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
94
+ > IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
95
+ > CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
96
+ > TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
97
+ > SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,37 @@
1
+ = bitly
2
+
3
+ == DESCRIPTION:
4
+
5
+ A Ruby API for version 3 of the http://bit.ly API, including j.mp and bitly.Pro support.
6
+
7
+ http://api.bit.ly
8
+
9
+ == INSTALLATION:
10
+
11
+ <tt>gem install bitly</tt>
12
+
13
+ == USAGE:
14
+
15
+ Create a client using your username and API key from http://bit.ly
16
+
17
+ <tt>bitly = Bitly.new(username, api_key)</tt>
18
+
19
+ Then use that client to shorten or expand urls and hashes.
20
+
21
+ <tt>bitly.shorten('http://google.com')</tt>
22
+
23
+ See the {documentation}[http://philnash.github.com/bitly/rdoc/index.html] for more details.
24
+
25
+ == Note on Patches/Pull Requests
26
+
27
+ * Fork the project.
28
+ * Make your feature addition or bug fix.
29
+ * Add tests for it. This is important so I don't break it in a
30
+ future version unintentionally.
31
+ * Commit, do not mess with rakefile, version, or history.
32
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
33
+ * Send me a pull request. Bonus points for topic branches.
34
+
35
+ == Copyright
36
+
37
+ Copyright (c) 2010 philnash. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "bitlyr"
7
+ gem.summary = "A ruby wrapper for the bit.ly API"
8
+ gem.description = <<-DESCRIPTION
9
+ A ruby wrapper for version 3 of the bit.ly API
10
+ Supports Login/ApiKey & OAuth authentication
11
+ DESCRIPTION
12
+ gem.email = "jonathon.scott.storer@gmail.com"
13
+ gem.homepage = "http://github.com/jonstorer/bitlyr"
14
+ gem.authors = ["jonstorer"]
15
+ gem.add_dependency 'httparty', ">= 0.7.6"
16
+ gem.add_dependency 'crack', ">= 0.1.4"
17
+ gem.add_dependency 'oauth2', '>= 0.1.1'
18
+ gem.add_development_dependency "shoulda", ">= 0"
19
+ gem.add_development_dependency "jeweler", ">= 1.4.0"
20
+ gem.add_development_dependency "rcov", ">= 0"
21
+ gem.add_development_dependency "mocha", ">= 0.10.0"
22
+ gem.add_development_dependency "fakeweb", ">= 1.2.8"
23
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
24
+ end
25
+
26
+ require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'lib' << 'test'
29
+ test.pattern = 'test/**/test_*.rb'
30
+ test.verbose = true
31
+ end
32
+
33
+ task :default => :test
34
+
35
+ require 'rake/rdoctask'
36
+ Rake::RDocTask.new do |rdoc|
37
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
38
+
39
+ rdoc.rdoc_dir = 'rdoc'
40
+ rdoc.title = "bitlyr #{version}"
41
+ rdoc.rdoc_files.include('README*')
42
+ rdoc.rdoc_files.include('lib/**/*.rb')
43
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.9.0
data/bitlyr.gemspec ADDED
@@ -0,0 +1,154 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "bitlyr"
8
+ s.version = "0.9.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jonstorer"]
12
+ s.date = "2012-01-17"
13
+ s.description = "A ruby wrapper for version 3 of the bit.ly API\nSupports Login/ApiKey & OAuth authentication\n"
14
+ s.email = "jonathon.scott.storer@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ "History.txt",
22
+ "LICENSE",
23
+ "README.md",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bitlyr.gemspec",
28
+ "lib/bitlyr.rb",
29
+ "lib/bitlyr/client.rb",
30
+ "lib/bitlyr/country.rb",
31
+ "lib/bitlyr/day.rb",
32
+ "lib/bitlyr/error.rb",
33
+ "lib/bitlyr/lib/core_ext/hash.rb",
34
+ "lib/bitlyr/lib/core_ext/string.rb",
35
+ "lib/bitlyr/missing_url.rb",
36
+ "lib/bitlyr/realtime_link.rb",
37
+ "lib/bitlyr/referrer.rb",
38
+ "lib/bitlyr/response.rb",
39
+ "lib/bitlyr/strategy/access_token.rb",
40
+ "lib/bitlyr/strategy/api_key.rb",
41
+ "lib/bitlyr/strategy/base.rb",
42
+ "lib/bitlyr/strategy/oauth.rb",
43
+ "lib/bitlyr/url.rb",
44
+ "lib/bitlyr/user.rb",
45
+ "test/fixtures/9uX1TE.json",
46
+ "test/fixtures/9uX1TEclicks.json",
47
+ "test/fixtures/9uX1TEclicks2.json",
48
+ "test/fixtures/9uX1TEinfo.json",
49
+ "test/fixtures/9uX1TEinfo2.json",
50
+ "test/fixtures/auth_fail.json",
51
+ "test/fixtures/auth_success.json",
52
+ "test/fixtures/betaworks.json",
53
+ "test/fixtures/betaworks2.json",
54
+ "test/fixtures/betaworks_jmp.json",
55
+ "test/fixtures/betaworks_other_user.json",
56
+ "test/fixtures/bitly9uX1TE.json",
57
+ "test/fixtures/bitly_pro_domain.json",
58
+ "test/fixtures/clicks_by_day.json",
59
+ "test/fixtures/clicks_by_day1.json",
60
+ "test/fixtures/clicks_by_day2.json",
61
+ "test/fixtures/clicks_by_minute1_url.json",
62
+ "test/fixtures/clicks_by_minute2_url.json",
63
+ "test/fixtures/clicks_by_minute_hash.json",
64
+ "test/fixtures/clicks_by_minute_hashes.json",
65
+ "test/fixtures/country_hash.json",
66
+ "test/fixtures/country_hash2.json",
67
+ "test/fixtures/country_url.json",
68
+ "test/fixtures/failure.json",
69
+ "test/fixtures/invalid_bitly_pro_domain.json",
70
+ "test/fixtures/invalid_credentials.json",
71
+ "test/fixtures/invalid_domain.json",
72
+ "test/fixtures/invalid_user.json",
73
+ "test/fixtures/invalid_x_api_key.json",
74
+ "test/fixtures/lookup_multiple_url.json",
75
+ "test/fixtures/lookup_not_real_url.json",
76
+ "test/fixtures/lookup_single_url.json",
77
+ "test/fixtures/missing_hash.json",
78
+ "test/fixtures/multiple_info.json",
79
+ "test/fixtures/multiple_url_click.json",
80
+ "test/fixtures/multiple_urls.json",
81
+ "test/fixtures/not_bitly_pro_domain.json",
82
+ "test/fixtures/not_found_info.json",
83
+ "test/fixtures/referrer_hash.json",
84
+ "test/fixtures/referrer_hash2.json",
85
+ "test/fixtures/referrer_url.json",
86
+ "test/fixtures/success.json",
87
+ "test/fixtures/url_info.json",
88
+ "test/fixtures/user_clicks.json",
89
+ "test/fixtures/user_countries.json",
90
+ "test/fixtures/user_realtime_links.json",
91
+ "test/fixtures/user_referrers.json",
92
+ "test/fixtures/valid_user.json",
93
+ "test/integration/strategy/test_api_key.rb",
94
+ "test/integration/strategy/test_oauth.rb",
95
+ "test/integration/test_client.rb",
96
+ "test/integration/test_user.rb",
97
+ "test/test_helper.rb",
98
+ "test/unit/core_ext/test_hash.rb",
99
+ "test/unit/core_ext/test_string.rb",
100
+ "test/unit/strategy/test_access_token.rb",
101
+ "test/unit/strategy/test_api_key.rb",
102
+ "test/unit/strategy/test_base.rb",
103
+ "test/unit/strategy/test_oauth.rb",
104
+ "test/unit/test_bitly.rb",
105
+ "test/unit/test_client.rb",
106
+ "test/unit/test_country.rb",
107
+ "test/unit/test_day.rb",
108
+ "test/unit/test_error.rb",
109
+ "test/unit/test_missing.rb",
110
+ "test/unit/test_realtime_link.rb",
111
+ "test/unit/test_referrer.rb",
112
+ "test/unit/test_response.rb",
113
+ "test/unit/test_url.rb",
114
+ "test/unit/test_user.rb"
115
+ ]
116
+ s.homepage = "http://github.com/jonstorer/bitlyr"
117
+ s.require_paths = ["lib"]
118
+ s.rubygems_version = "1.8.10"
119
+ s.summary = "A ruby wrapper for the bit.ly API"
120
+
121
+ if s.respond_to? :specification_version then
122
+ s.specification_version = 3
123
+
124
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
125
+ s.add_runtime_dependency(%q<httparty>, [">= 0.7.6"])
126
+ s.add_runtime_dependency(%q<crack>, [">= 0.1.4"])
127
+ s.add_runtime_dependency(%q<oauth2>, [">= 0.1.1"])
128
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
129
+ s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
130
+ s.add_development_dependency(%q<rcov>, [">= 0"])
131
+ s.add_development_dependency(%q<mocha>, [">= 0.10.0"])
132
+ s.add_development_dependency(%q<fakeweb>, [">= 1.2.8"])
133
+ else
134
+ s.add_dependency(%q<httparty>, [">= 0.7.6"])
135
+ s.add_dependency(%q<crack>, [">= 0.1.4"])
136
+ s.add_dependency(%q<oauth2>, [">= 0.1.1"])
137
+ s.add_dependency(%q<shoulda>, [">= 0"])
138
+ s.add_dependency(%q<jeweler>, [">= 1.4.0"])
139
+ s.add_dependency(%q<rcov>, [">= 0"])
140
+ s.add_dependency(%q<mocha>, [">= 0.10.0"])
141
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
142
+ end
143
+ else
144
+ s.add_dependency(%q<httparty>, [">= 0.7.6"])
145
+ s.add_dependency(%q<crack>, [">= 0.1.4"])
146
+ s.add_dependency(%q<oauth2>, [">= 0.1.1"])
147
+ s.add_dependency(%q<shoulda>, [">= 0"])
148
+ s.add_dependency(%q<jeweler>, [">= 1.4.0"])
149
+ s.add_dependency(%q<rcov>, [">= 0"])
150
+ s.add_dependency(%q<mocha>, [">= 0.10.0"])
151
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
152
+ end
153
+ end
154
+
@@ -0,0 +1,153 @@
1
+ module Bitlyr
2
+
3
+ # The client is the main part of this gem. You need to initialize the client with your
4
+ # username and API key and then you will be able to use the client to perform
5
+ # all the rest of the actions available through the API.
6
+ class Client
7
+ extend Forwardable
8
+
9
+ delegate [ :validate, :valid? ] => :strategy
10
+
11
+ # Requires a Bitlyr::Strategy
12
+ def initialize(strategy)
13
+ raise ArgumentError, "Requires a Bitlyr::Strategy" unless strategy.is_a?(Bitlyr::Strategy::Base)
14
+
15
+ @strategy = strategy
16
+ end
17
+
18
+ # Checks whether a domain is a Bitly Pro Domain
19
+ def bitly_pro_domain(domain)
20
+ response = get(:bitly_pro_domain, :domain => domain)
21
+ return response['bitly_pro_domain']
22
+ end
23
+ alias :pro? :bitly_pro_domain
24
+
25
+ # Shortens a long url
26
+ #
27
+ # Options can be:
28
+ #
29
+ # [domain] choose bit.ly or j.mp (bit.ly is default)
30
+ #
31
+ # [x_login and x_apiKey] add this link to another user's history (both required)
32
+ #
33
+ def shorten(long_url, options={})
34
+ response = get(:shorten, { :longUrl => long_url }.merge(options))
35
+ return Bitlyr::Url.new(self, response)
36
+ end
37
+
38
+ # Expands either a hash, short url or array of either.
39
+ #
40
+ # Returns the results in the order they were entered
41
+ def expand(input)
42
+ get_method(:expand, input)
43
+ end
44
+
45
+ # Expands either a hash, short url or array of either and gets click data too.
46
+ #
47
+ # Returns the results in the order they were entered
48
+ def clicks(input)
49
+ get_method(:clicks, input)
50
+ end
51
+
52
+ # Like expand, but gets the title of the page and who created it
53
+ def info(input)
54
+ get_method(:info, input)
55
+ end
56
+
57
+ # Looks up the short url and global hash of a url or array of urls
58
+ #
59
+ # Returns the results in the order they were entered
60
+ def lookup(input)
61
+ input = input.to_a
62
+ response = get(:lookup, :url => input)
63
+ results = response['lookup'].inject([]) do |results, url|
64
+ url['long_url'] = url.delete('url')
65
+ if url['error'].nil?
66
+ # builds the results array in the same order as the input
67
+ results[input.index(url['long_url'])] = Bitlyr::Url.new(self, url)
68
+ else
69
+ results[input.index(url['long_url'])] = Bitlyr::MissingUrl.new(url)
70
+ end
71
+ # remove the key from the original array, in case the same hash/url was entered twice
72
+ input[input.index(url['long_url'])] = nil
73
+ results
74
+ end
75
+ return results.length > 1 ? results : results[0]
76
+ end
77
+
78
+ # Expands either a short link or hash and gets the referrer data for that link
79
+ #
80
+ # This method does not take an array as an input
81
+ def referrers(input)
82
+ get_single_method(:referrers, input)
83
+ end
84
+
85
+ # Expands either a short link or hash and gets the country data for that link
86
+ #
87
+ # This method does not take an array as an input
88
+ def countries(input)
89
+ get_single_method(:countries, input)
90
+ end
91
+
92
+ # Takes a short url, hash or array of either and gets the clicks by minute of each of the last hour
93
+ def clicks_by_minute(input)
94
+ get_method(:clicks_by_minute, input)
95
+ end
96
+
97
+ # Takes a short url, hash or array of either and gets the clicks by day
98
+ def clicks_by_day(input, options={})
99
+ options.reject! { |k, v| k.to_s != 'days' }
100
+ get_method(:clicks_by_day, input, options)
101
+ end
102
+
103
+ private
104
+
105
+ def strategy
106
+ @strategy
107
+ end
108
+
109
+ def is_a_short_url?(input)
110
+ input.match(/^http:\/\//)
111
+ end
112
+
113
+ def get_single_method(method, input)
114
+ raise ArgumentError.new("This method only takes a hash or url input") unless input.is_a? String
115
+
116
+ key = is_a_short_url?(input) ? :shortUrl : :hash
117
+
118
+ response = get(method, key => input.to_a)
119
+ return Bitlyr::Url.new(self, response)
120
+ end
121
+
122
+ def get_method(method, input, options={})
123
+ options.symbolize_keys!
124
+ input = input.to_a
125
+
126
+ input.each do |i|
127
+ key = is_a_short_url?(i) ? :shortUrl : :hash
128
+ (options[key] ||= []) << i
129
+ end
130
+
131
+ response = get(method, options)
132
+
133
+ results = response[method.to_s].inject([]) do |results, url|
134
+ result_index = input.index(url['short_url'] || url['hash']) || input.index(url['global_hash'])
135
+
136
+ if url['error'].nil?
137
+ # builds the results array in the same order as the input
138
+ results[result_index] = Bitlyr::Url.new(self, url)
139
+ else
140
+ results[result_index] = Bitlyr::MissingUrl.new(url)
141
+ end
142
+ # remove the key from the original array, in case the same hash/url was entered twice
143
+ input[result_index] = nil
144
+ results
145
+ end
146
+ return results.length > 1 ? results : results[0]
147
+ end
148
+
149
+ def get(method, options={})
150
+ strategy.request(:get, method, options)
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,10 @@
1
+ module Bitlyr
2
+ class Country
3
+ attr_reader :clicks, :country
4
+
5
+ def initialize(options = {})
6
+ @clicks = options['clicks']
7
+ @country = options['country']
8
+ end
9
+ end
10
+ end
data/lib/bitlyr/day.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Bitlyr
2
+
3
+ # Day objects are created by the clicks_by_day method of a url
4
+ class Day
5
+ attr_reader :clicks, :day_start
6
+
7
+ def initialize(options = {})
8
+ @clicks = options['clicks']
9
+ @day_start = Time.at(options['day_start']) if options['day_start']
10
+ end
11
+ end
12
+ end