Permalink
Browse files

App is little more modular.

  • Loading branch information...
1 parent b071bc2 commit d9fb09cf2f2519ffd6a7f2c2559d959bbf2ab0d4 Štefan Ľupták committed May 25, 2012
Showing with 42 additions and 9 deletions.
  1. +6 −3 README.md
  2. +1 −2 config/gitlab_hook.yml.erb
  3. +2 −3 gitlab_hook.rb
  4. +13 −0 lib/bitly_client.rb
  5. +2 −0 lib/gitlab_hook.rb
  6. +0 −1 lib/hook_parser.rb
  7. +18 −0 lib/twitter_client.rb
View
@@ -10,15 +10,18 @@
* Now in _Settings_ tab, set _Access:_ to _Read and Write_ and save it.
* Keep this page open or copy all the tokens and keys from _Details_ tab. You'll need them in a while.
+### Bit.ly
+* If you don't have account on bit.ly, create one.
+* Log into your account, and copy your __Api Key__ from _Settings_ tab.
+
### Your computer
* Clone this repository: `git clone git@github.com:SmartMedia/gitlab-hook.git`
* Create Heroku Cedar application: `heroku create <APP_NAME> --stack cedar`
* Setup variables based on your Twitter _Details_ tab:
```bash
heroku config:add \
-SHORTENER_HOSTNAME='http://<APP_NAME>.herokuapp.com' \
-SHORTENER_ACCESS_TOKEN='' \
+GITLAB_ACCESS_TOKEN='' \
TWITTER_CONSUMER_KEY='' \
TWITTER_CONSUMER_SECRET='' \
TWITTER_OAUTH_TOKEN='' \
@@ -32,6 +35,6 @@ TWITTER_OAUTH_TOKEN_SECRET=''`
* Open your project.
* Select _Hooks_ tab.
* Fill out URL of your Heroku app with `access_token` parameter.
-(eg. `http://<APP_NAME>.herokuapp.com/?access_token=<SHORTENER_ACCESS_TOKEN>`)
+(eg. `http://<APP_NAME>.herokuapp.com/?access_token=<GITLAB_ACCESS_TOKEN>`)
* Press _"Test Hook"_
* Enjoy your Twitter timeline.
@@ -1,5 +1,4 @@
-hostname: <%= ENV['SHORTENER_HOSTNAME'] || '' %> # URL of your Heroku app
-access_token: <%= ENV['SHORTENER_ACCESS_TOKEN'] || '' %> # random access token, passed as parameter from GitLab
+access_token: <%= ENV['GITLAB_ACCESS_TOKEN'] || '' %> # random access token, passed as parameter from GitLab
twitter:
consumer_key: <%= ENV['TWITTER_CONSUMER_KEY'] || '' %>
consumer_secret: <%= ENV['TWITTER_CONSUMER_SECRET'] || '' %>
View
@@ -8,9 +8,8 @@
configure do
CONFIG = GitLabHook::Config.load
- TwitterClient = Twitter::Client.new(CONFIG[:twitter])
- Bitly.use_api_version_3
- BitlyClient = Bitly.new(CONFIG[:bitly][:username], CONFIG[:bitly][:api_key])
+ TwitterClient = GitLabHook::TwitterClient.new
+ BitlyClient = GitLabHook::BitlyClient.new
end
post '*' do
View
@@ -0,0 +1,13 @@
+module GitLabHook
+ class BitlyClient
+
+ attr_reader :client
+
+ def initialize
+ config = GitLabHook::Config.config
+ @client = Bitly.new(config[:bitly][:username], config[:bitly][:api_key])
+ Bitly.use_api_version_3
+ end
+
+ end
+end
View
@@ -1,2 +1,4 @@
require_relative 'config'
+require_relative 'bitly_client'
+require_relative 'twitter_client'
require_relative 'hook_parser'
View
@@ -22,7 +22,6 @@ def parse
url = shortener.shorten(gitlab_url)
msg = "[#{repo_name}] #{url.short_url} #{user_name} - #{message}"
- msg = msg[0..136] + '...' if msg.size > 140
@messages << msg
end
View
@@ -0,0 +1,18 @@
+module GitLabHook
+ class TwitterClient
+
+ attr_reader :client
+
+ def initialize
+ config = GitLabHook::Config.config
+ @client = Twitter::Client.new(config[:twitter])
+ client
+ end
+
+ def update(msg)
+ msg = msg[0..136] + '...' if msg.size > 140
+ client.update(msg)
+ end
+
+ end
+end

0 comments on commit d9fb09c

Please sign in to comment.