bluetail 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gems +1 -0
- data/.gems-test +1 -0
- data/LICENSE +8 -0
- data/README.md +54 -0
- data/bluetail.gemspec +16 -0
- data/lib/bluetail.rb +47 -0
- data/test/unit/bluetail_test.rb +47 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 858a923e3d1a3eb419294fcd308e60ceb65a293b
|
4
|
+
data.tar.gz: ab6397b8be6ab43bcbd1fc2bbe1e16bd2339750b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dfa304a403d6b2087a7cc8494820486097b7eec971e2a4e1561008906e2451408b27ee8f47c144c14459947d5de9df4163494b1a316cbdeb5c3fe2cf58afe9ef
|
7
|
+
data.tar.gz: 3803f10c09c281e4bebbf23e0cf9f357c0f130221d3d4333df32e34e69b1e60e99eacedc381521bd4349b9eac29aadd91561c7ab52bea2958dcd7aeb8e9b1ee7
|
data/.gems
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
simple_oauth -v 0.2.0
|
data/.gems-test
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
mocha -v 1.1.0
|
data/LICENSE
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Copyright (C) 2014 Three Funky Monkeys
|
2
|
+
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
|
+
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
7
|
+
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
##Bluetail
|
2
|
+
|
3
|
+
Named after a kind of blue bird, Bluetail is a small, easy to use library to make Twitter posts with your apps.
|
4
|
+
|
5
|
+
###Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install bluetail
|
9
|
+
```
|
10
|
+
|
11
|
+
###Pre-requisites
|
12
|
+
|
13
|
+
You'll need to define an application with write permissions in your twitter account to be able to use Bluetail. So, go to http://dev.twitter.com, sign in, create your application and make sure it has write permissions.
|
14
|
+
|
15
|
+
Then go to the `API Keys` tab for your Application Management page, and generate an access token for it.
|
16
|
+
|
17
|
+
You may have to wait a couple of seconds until Twitter makes your token visible and then you're ready to go.
|
18
|
+
|
19
|
+
From that page, you will need:
|
20
|
+
|
21
|
+
* API Key
|
22
|
+
* API Secret
|
23
|
+
* Access Token
|
24
|
+
* Access Token Secret
|
25
|
+
|
26
|
+
Copy them and make sure you have them accessible within your application (a config file, env vars, whatever you find more useful)
|
27
|
+
|
28
|
+
###Usage
|
29
|
+
|
30
|
+
You need to instantiate an object with the OAuth settings you copied before, and then you can just tweet:
|
31
|
+
|
32
|
+
```Ruby
|
33
|
+
require 'bluetail'
|
34
|
+
|
35
|
+
oauth_settings = {
|
36
|
+
:consumer_key => ENV["BLUETAIL_API_KEY"],
|
37
|
+
:consumer_secret => ENV["BLUETAIL_API_SECRET"],
|
38
|
+
:token => ENV["BLUETAIL_TOKEN"],
|
39
|
+
:token_secret => ENV["BLUETAIL_TOKEN_SECRET"]}
|
40
|
+
|
41
|
+
bird = Bluetail.new(oauth_settings)
|
42
|
+
|
43
|
+
bird.tweet("Look ma! I'm twitting")
|
44
|
+
```
|
45
|
+
|
46
|
+
Optionally, you can specify a log file in the constructor, if you don't do it, it will log to STDOUT by default.
|
47
|
+
|
48
|
+
```Ruby
|
49
|
+
bird = Bluetail.new(oauth_settings, "/var/log/my-tweets-log-file.log")
|
50
|
+
```
|
51
|
+
|
52
|
+
That's it, it's really simple to use.
|
53
|
+
|
54
|
+
Hope you enjoy it!
|
data/bluetail.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "bluetail"
|
5
|
+
s.version = "1.0"
|
6
|
+
s.summary = "A Twitter notifier"
|
7
|
+
s.license = "MIT"
|
8
|
+
s.description = "A simple library to create tweets"
|
9
|
+
s.authors = ["Lautaro Orazi", "Leonardo Mateo"]
|
10
|
+
s.email = ["taro@threefunkymonkeys.com", "kandalf@threefunkymonkeys.com"]
|
11
|
+
s.homepage = "https://github.com/threefunkymonkeys/bluetail"
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.add_dependency "simple_oauth", '~> 0.2'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
end
|
data/lib/bluetail.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'simple_oauth'
|
2
|
+
require 'net/http'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
class Bluetail
|
6
|
+
@@url = "https://api.twitter.com/1.1/statuses/update.json"
|
7
|
+
|
8
|
+
def initialize(oauth_settings = {}, log_file = STDOUT)
|
9
|
+
@oauth_settings = oauth_settings
|
10
|
+
@logger = Logger.new(log_file)
|
11
|
+
end
|
12
|
+
|
13
|
+
def tweet(status)
|
14
|
+
raise RuntimeError.new("Status too long") if status.length > 140
|
15
|
+
|
16
|
+
header = SimpleOAuth::Header.new("POST", @@url, {status: status}, @oauth_settings)
|
17
|
+
body = URI.encode("status=#{status}")
|
18
|
+
uri = URI(@@url)
|
19
|
+
request = create_request_for(uri.path, header, body)
|
20
|
+
|
21
|
+
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
|
22
|
+
response = http.request request
|
23
|
+
|
24
|
+
if response.code.to_s == "200"
|
25
|
+
@logger.info("Success")
|
26
|
+
else
|
27
|
+
@logger.error("#{response.code} - #{response.body}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def create_request_for(path, header, body)
|
34
|
+
|
35
|
+
request = Net::HTTP::Post.new(path)
|
36
|
+
|
37
|
+
request.body = body
|
38
|
+
request["Accept"] = "*/*"
|
39
|
+
request["Connection"] = "close"
|
40
|
+
request["User-Agent"] = "Bluetail Notifier 1.0"
|
41
|
+
request["Content-Type"] = "application/x-www-form-urlencoded"
|
42
|
+
request["Authorization"] = header.to_s
|
43
|
+
request["Content-Length"] = body.length
|
44
|
+
request["Host"] = "api.twitter.com"
|
45
|
+
request
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'mocha/mini_test'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
require_relative '../lib/bluetail'
|
7
|
+
|
8
|
+
describe 'Bluetail' do
|
9
|
+
def setup
|
10
|
+
@response = OpenStruct.new(
|
11
|
+
:code => 200,
|
12
|
+
:body => "Fake Response"
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should post to Twitter API' do
|
17
|
+
api_url = "https://api.twitter.com/1.1/statuses/update.json"
|
18
|
+
oauth_settings = {
|
19
|
+
:consumer_key => ENV["BLUETAIL_API_KEY"],
|
20
|
+
:consumer_secret => ENV["BLUETAIL_API_SECRET"],
|
21
|
+
:token => ENV["BLUETAIL_TOKEN"],
|
22
|
+
:token_secret => ENV["BLUETAIL_TOKEN_SECRET"]}
|
23
|
+
|
24
|
+
bird = Bluetail.new(oauth_settings)
|
25
|
+
|
26
|
+
status = "Test status"
|
27
|
+
|
28
|
+
SimpleOAuth::Header.expects(:new).with("POST", api_url, {status: status}, oauth_settings).returns({})
|
29
|
+
|
30
|
+
Net::HTTP.any_instance.expects(:request).returns(@response)
|
31
|
+
|
32
|
+
Logger.any_instance.expects(:info).with("Success").returns(true)
|
33
|
+
|
34
|
+
bird.tweet(status)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should reject long statuses' do
|
38
|
+
status = "a" * 141
|
39
|
+
|
40
|
+
bird = Bluetail.new({})
|
41
|
+
|
42
|
+
assert_raises(RuntimeError) do
|
43
|
+
bird.tweet(status)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bluetail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lautaro Orazi
|
8
|
+
- Leonardo Mateo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: simple_oauth
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.2'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.2'
|
28
|
+
description: A simple library to create tweets
|
29
|
+
email:
|
30
|
+
- taro@threefunkymonkeys.com
|
31
|
+
- kandalf@threefunkymonkeys.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".gems"
|
37
|
+
- ".gems-test"
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- bluetail.gemspec
|
41
|
+
- lib/bluetail.rb
|
42
|
+
- test/unit/bluetail_test.rb
|
43
|
+
homepage: https://github.com/threefunkymonkeys/bluetail
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.2.1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: A Twitter notifier
|
67
|
+
test_files: []
|