twitter_web_intents 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b0af1fa1b46514f3d8d2bc7c79635dcdc30e1c0
4
+ data.tar.gz: 162f2e96d2f58feef885df2453cc5511f4de6253
5
+ SHA512:
6
+ metadata.gz: 4f39bf5611212d5443ac60e733cfe18f5165db1908c2578a0dd5a6a26f1ad5c819e7d4a4a98fc42e00fa93f847e40425dbba1a8c518def357d1537c08d4cdc66
7
+ data.tar.gz: 8eb6c21285c60d9a237c7a091d367278ef4183893ef94a15ea5182e8e1717d2fd12b818c4ce4e150005cd55a08cd4129b1932faf43293d4d0403a20e7e267f0e
checksums.yaml.gz.sig ADDED
@@ -0,0 +1 @@
1
+ Z�(��B�����"?.R����A��F}?���Ćħ{動�YD/h�7��5�\�����ٳS��Wh��z"���J�L�էl��$��uKO�#:��i�9
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Richard Hollis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # TwitterWebIntents Ruby Gem
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/twitter_web_intents.png)][gem]
4
+ [![Build Status](https://secure.travis-ci.org/richhollis/twitter_web_intents.png?branch=master)][travis]
5
+ [![Dependency Status](https://gemnasium.com/richhollis/twitter_web_intents.png?travis)][gemnasium]
6
+ [![Coverage Status](https://coveralls.io/repos/richhollis/twitter_web_intents/badge.png?branch=master)][coveralls]
7
+
8
+ [gem]: https://rubygems.org/gems/twitter_web_intents
9
+ [travis]: http://travis-ci.org/richhollis/twitter_web_intents
10
+ [gemnasium]: https://gemnasium.com/richhollis/twitter_web_intents
11
+ [coveralls]: https://coveralls.io/r/richhollis/twitter_web_intents
12
+
13
+ Twitter Web Intents provides simple helper methods that return Twitter Web Intent URLs. The parameters that are passed are verified to ensure they are valid.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'twitter_web_intents'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install twitter_web_intents
28
+
29
+ ## Methods
30
+
31
+ ### get_search_url(query)
32
+
33
+ ```ruby
34
+ TwitterWebIntents.get_search_url('Parmigiano-Reggiano')
35
+ #=> "https://twitter.com/search?q=Parmigiano-Reggiano"
36
+ ```
37
+
38
+ ### get_profile_url(screen_name)
39
+
40
+ ```ruby
41
+ TwitterWebIntents.get_profile_url('warblealerts')
42
+ #=> "https://twitter.com/warblealerts
43
+ ```
44
+
45
+ ### get_status_url(screen_name, user_id)
46
+
47
+ ```ruby
48
+ TwitterWebIntents.get_status_url('warblealerts', 318705541666988034)
49
+ #=> "https://twitter.com/warblealerts/status/318705541666988034"
50
+ ```
51
+
52
+ ### get_user_url(params)
53
+
54
+ Valid parameters: [:screen_name, :user_id]
55
+
56
+ ```ruby
57
+ TwitterWebIntents.get_user_url({:screen_name => 'warblealerts'})
58
+ #=> "https://twitter.com/intent/user?screen_name=warblealerts"
59
+ ```
60
+
61
+ OR
62
+
63
+ ```ruby
64
+ TwitterWebIntents.get_user_url({:user_id => 102})
65
+ #=> https://twitter.com/intent/user/?user_id=102
66
+ ```
67
+
68
+ ### def get_favorite_url(params)
69
+
70
+ Valid parameters: [:tweet_id, :related]
71
+
72
+ ```ruby
73
+ TwitterWebIntents.get_favorite_url({:tweet_id => 318705541666988034, :related => ['warblealerts','richhollis']})
74
+ #=> "https://twitter.com/intent/favorite?related=warblealerts%2Crichhollis&tweet_id=318705541666988034"
75
+ ```
76
+
77
+ ### get_tweet_url(params)
78
+
79
+ Valid parameters: [:url, :via, :text, :in_reply_to, :hashtags, :related]
80
+
81
+ ```ruby
82
+ TwitterWebIntents.get_tweet_url({:url => 'http://warble.co', :via => 'richhollis', :text => 'hello world', :in_reply_to => 318705541666988034, :hashtags => '#warble', :related => 'warblealerts'})
83
+ #=> "https://twitter.com/intent/tweet?hashtags=%23warble&in_reply_to=318705541666988034&related=warblealerts&text=hello+world&url=http%3A%2F%2Fwarble.co&via=richhollis"
84
+ ```
85
+
86
+ ### get_retweet_url(params)
87
+
88
+ Valid parameters: [:tweet_id, :related]
89
+
90
+ ```ruby
91
+ TwitterWebIntents.get_retweet_url({:tweet_id => 318705541666988034, :related => ['warblealerts','richhollis']})
92
+ #=> "https://twitter.com/intent/retweet?related=warblealerts%2Crichhollis&tweet_id=318705541666988034"
93
+ ```
94
+
95
+ ## Contributing
96
+
97
+ 1. Fork it
98
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
99
+ 3. Commit your changes and ensure test coverage (`git commit -am 'Add some feature'`)
100
+ 4. Push to the branch (`git push origin my-new-feature`)
101
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :test => :spec
7
+ task :default => :spec
@@ -0,0 +1,62 @@
1
+ require 'uri'
2
+ require 'active_support/core_ext/object/to_query'
3
+
4
+ module TwitterWebIntents
5
+
6
+ class Intents
7
+
8
+ # https://dev.twitter.com/docs/intents
9
+
10
+ URL_BASE = "https://twitter.com/"
11
+
12
+ class << self
13
+
14
+ def get_search_url(query)
15
+ URL_BASE + "search?q=" + URI.escape(query)
16
+ end
17
+
18
+ def get_profile_url(screen_name)
19
+ URL_BASE + screen_name
20
+ end
21
+
22
+ def get_status_url(screen_name, user_id)
23
+ URL_BASE + "#{screen_name}/status/#{user_id}"
24
+ end
25
+
26
+ def get_user_url(params)
27
+ get_intent(:user, params, [:screen_name, :user_id])
28
+ end
29
+
30
+ def get_favorite_url(params)
31
+ get_intent(:favorite, params, [:tweet_id, :related])
32
+ end
33
+
34
+ def get_tweet_url(params)
35
+ get_intent(:tweet, params, [:url, :via, :text, :in_reply_to, :hashtags, :related])
36
+ end
37
+
38
+ def get_retweet_url(params)
39
+ get_intent(:retweet, params, [:tweet_id, :related])
40
+ end
41
+
42
+ private
43
+
44
+ def get_intent(type, params, valid)
45
+ URL_BASE + "intent/#{type.to_s}?#{get_parameters(type, params, valid).to_query}"
46
+ end
47
+
48
+ def get_parameters(type, params, valid)
49
+ counts = {}; hash = {}
50
+ params.each do |k,v|
51
+ raise ArgumentException.new("The parameter #{k} is not supported by the #{type} intent") if not valid.include?(k)
52
+ counts[k] = (counts[k].nil?) ? 1 : counts[k] += 1
53
+ hash[k] = v.is_a?(Array) ? v.join(",") : v
54
+ end
55
+ hash
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,3 @@
1
+ module TwitterWebIntents
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ require "twitter_web_intents/version"
2
+ require "twitter_web_intents/intents"
3
+
4
+ module TwitterWebIntents
5
+
6
+ class << self
7
+ def respond_to_missing?(method_name, include_private=false); Intents.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9"
8
+ def respond_to?(method_name, include_private=false); Intents.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9"
9
+
10
+ private
11
+
12
+ def method_missing(method_name, *args, &block)
13
+ return super unless Intents.respond_to?(method_name)
14
+ Intents.send(method_name, *args, &block)
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,21 @@
1
+ if RUBY_VERSION >= '1.9' # dont include <1.9 otherwise this breaks jruby-18mode
2
+ require 'coveralls'
3
+ require 'simplecov'
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start do
9
+ add_group 'Libraries', 'lib'
10
+ add_group 'Spec', 'spec'
11
+ end
12
+ end
13
+
14
+ require 'twitter_web_intents'
15
+
16
+ RSpec.configure do |config|
17
+ config.expect_with :rspec do |c|
18
+ c.syntax = :expect
19
+ end
20
+ config.color_enabled = true
21
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe TwitterWebIntents do
4
+
5
+ include TwitterWebIntents
6
+
7
+ subject { TwitterWebIntents }
8
+
9
+ describe "#get_search_url" do
10
+ it "returns correct url" do
11
+ expect(subject.get_search_url('#wshoppr')).to eq("https://twitter.com/search?q=%23wshoppr")
12
+ end
13
+ end
14
+
15
+ describe "#get_profile_url" do
16
+ it "returns correct url" do
17
+ expect(subject.get_profile_url('richhollis')).to eq("https://twitter.com/richhollis")
18
+ end
19
+ end
20
+
21
+ describe "#get_status_url" do
22
+ it "returns correct url" do
23
+ expect(subject.get_status_url('richhollis', 123456789)).to eq("https://twitter.com/richhollis/status/123456789")
24
+ end
25
+ end
26
+
27
+ describe "#get_user_url" do
28
+ it "returns correct url" do
29
+ expect(subject.get_user_url({:screen_name => 'richhollis'})).to eq("https://twitter.com/intent/user?screen_name=richhollis")
30
+ end
31
+ it "raises when parameter is invalid" do
32
+ expect{subject.get_user_url({:not_valid => 1})}.to raise_error
33
+ end
34
+ end
35
+
36
+ describe "#get_retweet_url" do
37
+ it "returns correct url" do
38
+ expect(subject.get_retweet_url({:tweet_id => 123456789})).to eq("https://twitter.com/intent/retweet?tweet_id=123456789")
39
+ end
40
+ it "raises when parameter is invalid" do
41
+ expect{subject.get_retweet_url({:not_valid => 1})}.to raise_error
42
+ end
43
+ end
44
+
45
+ describe "#get_favorite_url" do
46
+ it "returns correct url" do
47
+ expect(subject.get_favorite_url({:tweet_id => 123456789})).to eq("https://twitter.com/intent/favorite?tweet_id=123456789")
48
+ end
49
+ it "raises when parameter is invalid" do
50
+ expect{subject.get_favorite_url({:not_valid => 1})}.to raise_error
51
+ end
52
+ end
53
+
54
+ describe "#get_tweet_url" do
55
+ it "returns correct url for text" do
56
+ hash = {:text => "Intellectual property has the shelf life of a banana", :related => ['warblealerts', 'jesseddy', 'richhollis']}
57
+ expect(subject.get_tweet_url(hash)).to eq("https://twitter.com/intent/tweet?related=warblealerts%2Cjesseddy%2Crichhollis&text=Intellectual+property+has+the+shelf+life+of+a+banana")
58
+ end
59
+ it "returns correct url for in_reply_to" do
60
+ hash = {:in_reply_to => 123456789, :via => 'warblealerts'}
61
+ expect(subject.get_tweet_url(hash)).to eq("https://twitter.com/intent/tweet?in_reply_to=123456789&via=warblealerts")
62
+ end
63
+ it "raises when parameter is invalid" do
64
+ expect{subject.get_tweet_url({:not_valid => 1})}.to raise_error
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'twitter_web_intents/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "twitter_web_intents"
8
+ spec.version = TwitterWebIntents::VERSION
9
+ spec.authors = ["Richard Hollis"]
10
+ spec.email = ["richhollis@gmail.com"]
11
+ spec.description = %q{Simple helper methods that return Twitter Web Intent URLs}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/richhollis/twitter_web_intents"
14
+ spec.license = "MIT"
15
+
16
+ spec.cert_chain = ['certs/richhollis.pem']
17
+ spec.signing_key = File.expand_path("~/.gem/private_key.pem") if $0 =~ /gem\z/
18
+
19
+ spec.files = %w(LICENSE.txt README.md Rakefile twitter_web_intents.gemspec)
20
+ spec.files += Dir.glob("lib/**/*.rb")
21
+ spec.files += Dir.glob("spec/**/*")
22
+
23
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
+ spec.require_paths = ["lib"]
26
+ spec.test_files = Dir.glob('spec/**/*')
27
+
28
+ spec.add_dependency "activesupport", ['>= 3.0', '< 4.1']
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.3"
31
+ spec.add_development_dependency "rake"
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_development_dependency "simplecov" if RUBY_VERSION >= '1.9'
34
+ spec.add_development_dependency "coveralls"
35
+
36
+ end
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ���\Sg��i2K����js/m����r#GT���e3Ugqڹt;
2
+ �POW8!{H�|�^\�0�
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twitter_web_intents
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Richard Hollis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDApyaWNo
14
+ aG9sbGlzMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/I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
31
+ -----END CERTIFICATE-----
32
+ date: 2013-04-10 00:00:00.000000000 Z
33
+ dependencies:
34
+ - !ruby/object:Gem::Dependency
35
+ name: activesupport
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - - <
42
+ - !ruby/object:Gem::Version
43
+ version: '4.1'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '3.0'
51
+ - - <
52
+ - !ruby/object:Gem::Version
53
+ version: '4.1'
54
+ - !ruby/object:Gem::Dependency
55
+ name: bundler
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '1.3'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '1.3'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rake
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: simplecov
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: coveralls
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ description: Simple helper methods that return Twitter Web Intent URLs
125
+ email:
126
+ - richhollis@gmail.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - LICENSE.txt
132
+ - README.md
133
+ - Rakefile
134
+ - twitter_web_intents.gemspec
135
+ - lib/twitter_web_intents.rb
136
+ - lib/twitter_web_intents/version.rb
137
+ - lib/twitter_web_intents/intents.rb
138
+ - spec/spec_helper.rb
139
+ - spec/twitter_web_intents_spec.rb
140
+ homepage: https://github.com/richhollis/twitter_web_intents
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.0.0.rc.2
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: Simple helper methods that return Twitter Web Intent URLs
164
+ test_files:
165
+ - spec/spec_helper.rb
166
+ - spec/twitter_web_intents_spec.rb
metadata.gz.sig ADDED
Binary file