Permalink
Browse files

Merge remote-tracking branch 'xing/master'

Conflicts:
	README.md
  • Loading branch information...
2 parents 7483dd5 + fc19866 commit ffe838fab1a39ba94e50973d5c1c2da12a1b882e @DAddYE committed Aug 9, 2011
Showing with 33 additions and 3 deletions.
  1. +1 −0 .gitignore
  2. +6 −1 README.md
  3. +26 −2 lib/githubwatcher.rb
View
@@ -2,3 +2,4 @@
.bundle
Gemfile.lock
pkg/*
+.rvmrc
View
@@ -73,6 +73,11 @@ Restart the deamon
$ githubwatcher restart
```
+## Using a different API
+
+Simply edit `~/.githubwatcher/api.yaml` and set a custom url and api version. If you are using GitHub:FI the
+version has to be v2 for now.
+
## Working with Ruby Forever
``` sh
@@ -94,4 +99,4 @@ in this way will be generated the `Gemfile.lock`, in future you will be able to
## Author
-DAddYE, you can follow me on twitter [@daddye](http://twitter.com/daddye)
+DAddYE, you can follow me on twitter [@daddye](http://twitter.com/daddye)
View
@@ -9,16 +9,21 @@ module Githubwatcher
extend self
include HTTParty
+ API = File.expand_path("~/.githubwatcher/api.yaml")
WATCH = File.expand_path("~/.githubwatcher/repos.yaml")
DB = File.expand_path("~/.githubwatcher/db.yaml")
- base_uri 'https://api.github.com'
format :json
def setup
raise "You need to install growlnotify, use brew install growlnotify or install it from growl.info site" unless Growl.installed?
puts "Starting GitHub Watcher..."
+ unless File.exist?(API)
+ Dir.mkdir(File.dirname(API)) unless File.exist?(File.dirname(WATCH))
+ File.open(API, "w") { |f| f.write ["https://api.github.com", "v3"].to_yaml }
+ end
+
unless File.exist?(WATCH)
warn "Add the repositories you're willing to monitor editing: ~/.githubwatcher/repos.yaml"
Dir.mkdir(File.dirname(WATCH)) unless File.exist?(File.dirname(WATCH))
@@ -27,13 +32,16 @@ def setup
@_watch = YAML.load_file(WATCH)
@_repos = YAML.load_file(DB) if File.exist?(DB)
+ @base_uri, @api_version = YAML.load_file(API)
+
+ base_uri @base_uri
end
def start!
repos_was = repos.dup
watch.each do |value|
key, value = *value.split("/")
- r = get "/users/%s/repos" % key
+ r = get_repositories(key)
r.each do |repo|
next unless value.include?(repo["name"]) || value.include?("all")
puts "Quering #{repo["git_url"]}..."
@@ -89,4 +97,20 @@ def notify(title, text)
Growl.notify text, :title => title, :icon => File.expand_path("../../images/icon.png", __FILE__); sleep 0.2
puts "=> #{title}: #{text}"
end
+
+ def get_repositories(key)
+ r = get resource_url(key)
+ @api_version == "v3" ? r : r["repositories"]
+ end
+
+ def resource_url(key)
+ case @api_version
+ when "v3"
+ "/users/%s/repos" % key
+ when "v2"
+ "/api/v2/json/repos/show/%s" % key
+ else
+ raise "Unkown api version"
+ end
+ end
end

0 comments on commit ffe838f

Please sign in to comment.