devcenter 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/devcenter.rb +2 -0
- data/lib/devcenter/client.rb +23 -0
- data/lib/devcenter/commands/base.rb +6 -1
- data/lib/devcenter/commands/open.rb +4 -4
- data/lib/devcenter/commands/pull.rb +1 -1
- data/lib/devcenter/gem_version_checker.rb +22 -0
- data/lib/devcenter/helpers.rb +6 -6
- data/lib/devcenter/version.rb +1 -1
- metadata +4 -2
data/lib/devcenter.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require_relative 'devcenter/version'
|
2
|
+
require_relative 'devcenter/gem_version_checker'
|
2
3
|
require_relative 'devcenter/logger'
|
3
4
|
require_relative 'devcenter/helpers'
|
5
|
+
require_relative 'devcenter/client'
|
4
6
|
require_relative 'devcenter/previewer'
|
5
7
|
require_relative 'devcenter/coderay_extensions'
|
6
8
|
require_relative 'devcenter/cli'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'excon'
|
3
|
+
|
4
|
+
module Devcenter
|
5
|
+
|
6
|
+
module Client
|
7
|
+
include Devcenter::Helpers
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def head(args)
|
11
|
+
client.head(args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(args)
|
15
|
+
client.get(args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def client
|
19
|
+
@client ||= Excon.new(devcenter_base_url, :headers => { 'User-agent' => 'DevCenterCLI'})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -11,6 +11,11 @@ module Devcenter::Commands
|
|
11
11
|
include Devcenter::Helpers
|
12
12
|
|
13
13
|
def self.run(*args)
|
14
|
+
if Devcenter::GemVersionChecker.new_version_available?
|
15
|
+
say "devcenter has a new version available, please update with: gem install devcenter"
|
16
|
+
return unless agree('Continue executing your command? (yes/no)')
|
17
|
+
end
|
18
|
+
|
14
19
|
command = self.new(*args)
|
15
20
|
end
|
16
21
|
|
@@ -31,7 +36,7 @@ module Devcenter::Commands
|
|
31
36
|
|
32
37
|
def article_not_found!(slug)
|
33
38
|
message = ["No #{slug} article found."]
|
34
|
-
suggestions = JSON.parse(
|
39
|
+
suggestions = JSON.parse(Devcenter::Client.get(:path => search_api_path, :query => { :q => slug, :source => 'devcenter-cli' }).body)['devcenter']
|
35
40
|
suggestions.select!{ |s| article_url?(s['full_url']) }
|
36
41
|
suggestions.each{ |s| s['slug'] = slug_from_article_url(s['full_url']) }
|
37
42
|
unless suggestions.empty?
|
@@ -14,13 +14,13 @@ module Devcenter::Commands
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def run
|
17
|
-
|
18
|
-
log "Connecting to #{
|
19
|
-
head =
|
17
|
+
path = article_path(@slug)
|
18
|
+
log "Connecting to #{path}"
|
19
|
+
head = Devcenter::Client.head(:path => path)
|
20
20
|
case head.status
|
21
21
|
when 200
|
22
22
|
log "Page found, opening"
|
23
|
-
launchy = Launchy.open(
|
23
|
+
launchy = Launchy.open(devcenter_base_url + path)
|
24
24
|
launchy.join if launchy.respond_to?(:join)
|
25
25
|
when 301, 302
|
26
26
|
say "Redirected to #{head.headers['Location']}"
|
@@ -15,7 +15,7 @@ module Devcenter::Commands
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def run
|
18
|
-
response =
|
18
|
+
response = Devcenter::Client.get(path: article_api_path(@slug))
|
19
19
|
article_received = response.status == 200 && JSON.parse(response.body)['article'] && JSON.parse(response.body)['article']['id']
|
20
20
|
article_not_found!(@slug) unless article_received
|
21
21
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'version'
|
2
|
+
|
3
|
+
module Devcenter
|
4
|
+
|
5
|
+
module GemVersionChecker
|
6
|
+
|
7
|
+
def self.new_version_available?
|
8
|
+
remote = last_remote_version
|
9
|
+
remote && (Gem::Version.new(remote) > Gem::Version.new(Devcenter::VERSION))
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.last_remote_version
|
13
|
+
json = Excon.get('https://rubygems.org/api/v1/versions/devcenter.json').body
|
14
|
+
versions = JSON.parse(json).map{ |v| v['number'] }
|
15
|
+
versions.sort{ |a,b| Gem::Version.new(a) <=> Gem::Version.new(b) }.last
|
16
|
+
rescue
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/devcenter/helpers.rb
CHANGED
@@ -4,16 +4,16 @@ module Devcenter::Helpers
|
|
4
4
|
ENV['DEVCENTER_BASE_URL'] || 'https://devcenter.heroku.com'
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
"
|
7
|
+
def article_path(slug)
|
8
|
+
"/articles/#{slug}"
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
"#{
|
11
|
+
def article_api_path(slug)
|
12
|
+
"#{article_path(slug)}.json"
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
"
|
15
|
+
def search_api_path
|
16
|
+
"/articles.json"
|
17
17
|
end
|
18
18
|
|
19
19
|
def article_url?(url)
|
data/lib/devcenter/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devcenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-02-
|
13
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: listen
|
@@ -238,12 +238,14 @@ files:
|
|
238
238
|
- devcenter.gemspec
|
239
239
|
- lib/devcenter.rb
|
240
240
|
- lib/devcenter/cli.rb
|
241
|
+
- lib/devcenter/client.rb
|
241
242
|
- lib/devcenter/coderay_extensions.rb
|
242
243
|
- lib/devcenter/commands.rb
|
243
244
|
- lib/devcenter/commands/base.rb
|
244
245
|
- lib/devcenter/commands/open.rb
|
245
246
|
- lib/devcenter/commands/preview.rb
|
246
247
|
- lib/devcenter/commands/pull.rb
|
248
|
+
- lib/devcenter/gem_version_checker.rb
|
247
249
|
- lib/devcenter/helpers.rb
|
248
250
|
- lib/devcenter/layout.html
|
249
251
|
- lib/devcenter/logger.rb
|