githubwatcher 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -73,6 +73,11 @@ Restart the deamon
73
73
  $ githubwatcher restart
74
74
  ```
75
75
 
76
+ ## Using a different API
77
+
78
+ Simply edit `~/.githubwatcher/api.yaml` and set a custom url and api version. If you are using GitHub:FI the
79
+ version has to be v2 for now.
80
+
76
81
  ## Working with Ruby Forever
77
82
 
78
83
  ``` sh
@@ -94,4 +99,4 @@ in this way will be generated the `Gemfile.lock`, in future you will be able to
94
99
 
95
100
  ## Author
96
101
 
97
- DAddYE, you can follow me on twitter [@daddye](http://twitter.com/daddye)
102
+ DAddYE, you can follow me on twitter [@daddye](http://twitter.com/daddye)
@@ -9,16 +9,21 @@ module Githubwatcher
9
9
  extend self
10
10
  include HTTParty
11
11
 
12
+ API = File.expand_path("~/.githubwatcher/api.yaml")
12
13
  WATCH = File.expand_path("~/.githubwatcher/repos.yaml")
13
14
  DB = File.expand_path("~/.githubwatcher/db.yaml")
14
15
 
15
- base_uri 'https://api.github.com'
16
16
  format :json
17
17
 
18
18
  def setup
19
19
  raise "You need to install growlnotify, use brew install growlnotify or install it from growl.info site" unless Growl.installed?
20
20
  puts "Starting GitHub Watcher..."
21
21
 
22
+ unless File.exist?(API)
23
+ Dir.mkdir(File.dirname(API)) unless File.exist?(File.dirname(WATCH))
24
+ File.open(API, "w") { |f| f.write ["https://api.github.com", "v3"].to_yaml }
25
+ end
26
+
22
27
  unless File.exist?(WATCH)
23
28
  warn "Add the repositories you're willing to monitor editing: ~/.githubwatcher/repos.yaml"
24
29
  Dir.mkdir(File.dirname(WATCH)) unless File.exist?(File.dirname(WATCH))
@@ -27,13 +32,16 @@ module Githubwatcher
27
32
 
28
33
  @_watch = YAML.load_file(WATCH)
29
34
  @_repos = YAML.load_file(DB) if File.exist?(DB)
35
+ @base_uri, @api_version = YAML.load_file(API)
36
+
37
+ base_uri @base_uri
30
38
  end
31
39
 
32
40
  def start!
33
41
  repos_was = repos.dup
34
42
  watch.each do |value|
35
43
  key, value = *value.split("/")
36
- r = get "/users/%s/repos" % key
44
+ r = get_repositories(key)
37
45
  r.each do |repo|
38
46
  next unless value.include?(repo["name"]) || value.include?("all")
39
47
  puts "Quering #{repo["git_url"]}..."
@@ -89,4 +97,20 @@ module Githubwatcher
89
97
  Growl.notify text, :title => title, :icon => File.expand_path("../../images/icon.png", __FILE__); sleep 0.2
90
98
  puts "=> #{title}: #{text}"
91
99
  end
100
+
101
+ def get_repositories(key)
102
+ r = get resource_url(key)
103
+ @api_version == "v3" ? r : r["repositories"]
104
+ end
105
+
106
+ def resource_url(key)
107
+ case @api_version
108
+ when "v3"
109
+ "/users/%s/repos" % key
110
+ when "v2"
111
+ "/api/v2/json/repos/show/%s" % key
112
+ else
113
+ raise "Unkown api version"
114
+ end
115
+ end
92
116
  end
@@ -1,3 +1,3 @@
1
1
  module Githubwatcher
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: githubwatcher
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Davide D'Agostino
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-28 00:00:00 +02:00
18
+ date: 2011-08-09 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency