rest-gw2 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.gitmodules +3 -0
- data/README.md +76 -0
- data/Rakefile +13 -0
- data/config.ru +3 -0
- data/lib/rest-gw2.rb +5 -0
- data/lib/rest-gw2/client.rb +32 -0
- data/lib/rest-gw2/server.rb +89 -0
- data/lib/rest-gw2/view/bank.erb +25 -0
- data/rest-gw2.gemspec +43 -0
- data/task/README.md +54 -0
- data/task/gemgem.rb +316 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db66e083f2389a6f7e6607b09b3cebc8acf62037
|
4
|
+
data.tar.gz: 09e66dee7a294ef69d94fe9de9f273cb08aa59b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 673e5d69c6e911e91da4f32c6625ab77791be6edaf9e56bd8e739a6f5cc25f73a4132cff3b0710ac5acb99202e42c16557a5009262f1fd2953b13f481f81e250
|
7
|
+
data.tar.gz: e13ea78cd360116df6308f6a776a0e1505f51dda8c12d39b49889a24662c2d27cc92f928f8aaf961167d7f39635d35354deddd96c076a34240ee5370ef8311a1
|
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# rest-gw2 [](http://travis-ci.org/godfat/rest-gw2) [](https://coveralls.io/r/godfat/rest-gw2) [](https://gitter.im/godfat/rest-gw2)
|
2
|
+
|
3
|
+
by Lin Jen-Shin ([godfat](http://godfat.org))
|
4
|
+
|
5
|
+
## LINKS:
|
6
|
+
|
7
|
+
* [github](https://github.com/godfat/rest-gw2)
|
8
|
+
* [rubygems](https://rubygems.org/gems/rest-gw2)
|
9
|
+
* [rdoc](http://rdoc.info/github/godfat/rest-gw2)
|
10
|
+
|
11
|
+
## DESCRIPTION:
|
12
|
+
|
13
|
+
A very simple [Guild Wars 2 API](https://wiki.guildwars2.com/wiki/API:Main)
|
14
|
+
client built with [rest-core](https://github.com/godfat/rest-core).
|
15
|
+
|
16
|
+
There's also a bundled web application showing your items, serving as an
|
17
|
+
example using the client.
|
18
|
+
|
19
|
+
## FEATURES:
|
20
|
+
|
21
|
+
* Caching from rest-core for the win.
|
22
|
+
* Concurrency from rest-core for the win.
|
23
|
+
|
24
|
+
## REQUIREMENTS:
|
25
|
+
|
26
|
+
* Tested with MRI (official CRuby), Rubinius and JRuby.
|
27
|
+
* rest-core
|
28
|
+
* jellyfish (only for web application)
|
29
|
+
|
30
|
+
## INSTALLATION:
|
31
|
+
|
32
|
+
gem install rest-gw2
|
33
|
+
|
34
|
+
## SYNOPSIS:
|
35
|
+
|
36
|
+
``` ruby
|
37
|
+
require 'rest-gw2'
|
38
|
+
gw2 = RestGW2::Client.new(:access_token => '...')
|
39
|
+
gw2.get('account/bank') # => list of items in your bank
|
40
|
+
```
|
41
|
+
|
42
|
+
## Bundled Web Application:
|
43
|
+
|
44
|
+
If you would like to try it, run with:
|
45
|
+
|
46
|
+
env ACCESS_TOKEN=... rest-gw2-server
|
47
|
+
|
48
|
+
Or you could put your access token in a config file and point it with:
|
49
|
+
|
50
|
+
env RESTGW2_CONFIG=... rest-gw2-server
|
51
|
+
|
52
|
+
The format for the config file would be like:
|
53
|
+
|
54
|
+
ACCESS_TOKEN=...
|
55
|
+
|
56
|
+
## CONTRIBUTORS:
|
57
|
+
|
58
|
+
* Lin Jen-Shin (@godfat)
|
59
|
+
|
60
|
+
## LICENSE:
|
61
|
+
|
62
|
+
Apache License 2.0
|
63
|
+
|
64
|
+
Copyright (c) 2015, Lin Jen-Shin (godfat)
|
65
|
+
|
66
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
67
|
+
you may not use this file except in compliance with the License.
|
68
|
+
You may obtain a copy of the License at
|
69
|
+
|
70
|
+
<http://www.apache.org/licenses/LICENSE-2.0>
|
71
|
+
|
72
|
+
Unless required by applicable law or agreed to in writing, software
|
73
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
74
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
75
|
+
See the License for the specific language governing permissions and
|
76
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
begin
|
3
|
+
require "#{dir = File.dirname(__FILE__)}/task/gemgem"
|
4
|
+
rescue LoadError
|
5
|
+
sh 'git submodule update --init'
|
6
|
+
exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
|
7
|
+
end
|
8
|
+
|
9
|
+
Gemgem.init(dir) do |s|
|
10
|
+
s.name = 'rest-gw2'
|
11
|
+
s.version = '0.1.0'
|
12
|
+
%w[rest-core].each{ |g| s.add_runtime_dependency(g) }
|
13
|
+
end
|
data/config.ru
ADDED
data/lib/rest-gw2.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require 'rest-core'
|
3
|
+
|
4
|
+
module RestGW2
|
5
|
+
Client = RC::Builder.client do
|
6
|
+
use RC::DefaultSite , 'https://api.guildwars2.com/v2/'
|
7
|
+
use RC::DefaultHeaders, {'Accept' => 'application/json'}
|
8
|
+
use RC::Oauth2Header , 'Bearer', nil
|
9
|
+
|
10
|
+
use RC::Timeout , 10
|
11
|
+
use RC::ErrorHandler ,
|
12
|
+
lambda{ |env| RuntimeError.new(env[RC::RESPONSE_BODY]) }
|
13
|
+
use RC::ErrorDetectorHttp
|
14
|
+
|
15
|
+
use RC::JsonResponse , true
|
16
|
+
use RC::CommonLogger , nil
|
17
|
+
use RC::Cache , nil, 600
|
18
|
+
end
|
19
|
+
|
20
|
+
Client.include(Module.new{
|
21
|
+
def with_item_detail path, query={}
|
22
|
+
items = get(path, query)
|
23
|
+
ids = items.map{ |i| i && i['id'] }
|
24
|
+
|
25
|
+
detail = ids.compact.each_slice(5).map do |slice|
|
26
|
+
get('items', :ids => slice.join(','))
|
27
|
+
end.flatten.group_by{ |i| i['id'] }
|
28
|
+
|
29
|
+
items.map{ |i| i && detail[i['id']].first.merge('count' => i['count']) }
|
30
|
+
end
|
31
|
+
})
|
32
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
|
2
|
+
require 'dalli'
|
3
|
+
require 'jellyfish'
|
4
|
+
|
5
|
+
require 'erb'
|
6
|
+
|
7
|
+
module RestGW2
|
8
|
+
CONFIG = ENV['RESTGW2_CONFIG'] || File.expand_path("#{__dir__}/../../.env")
|
9
|
+
|
10
|
+
def self.extract_env path
|
11
|
+
return {} unless File.exist?(path)
|
12
|
+
Hash[File.read(path).strip.squeeze("\n").each_line.map do |line|
|
13
|
+
name, value = line.split('=')
|
14
|
+
[name, value.chomp] if name && value
|
15
|
+
end.compact]
|
16
|
+
end
|
17
|
+
|
18
|
+
extract_env(CONFIG).each do |k, v|
|
19
|
+
ENV[k] ||= v
|
20
|
+
end
|
21
|
+
|
22
|
+
module DalliExtension
|
23
|
+
def [] *args
|
24
|
+
get(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def []= *args
|
28
|
+
set(*args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def store *args
|
32
|
+
set(*args)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.cache
|
37
|
+
@cache ||= begin
|
38
|
+
client = Dalli::Client.new
|
39
|
+
client.extend(DalliExtension)
|
40
|
+
client
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class ServerCore
|
45
|
+
include Jellyfish
|
46
|
+
controller_include Module.new{
|
47
|
+
def render path
|
48
|
+
ERB.new(views(path)).result(binding)
|
49
|
+
end
|
50
|
+
|
51
|
+
def views path
|
52
|
+
@views ||= {}
|
53
|
+
@views[path] ||= File.read("#{__dir__}/view/#{path}.erb")
|
54
|
+
end
|
55
|
+
|
56
|
+
def item_title item
|
57
|
+
t = item['description']
|
58
|
+
t && t.unpack('U*').map{ |c| "&##{c};" }.join
|
59
|
+
end
|
60
|
+
|
61
|
+
def gw2
|
62
|
+
Client.new(:access_token => ENV['ACCESS_TOKEN'],
|
63
|
+
:log_method => env['rack.errors'].method(:puts),
|
64
|
+
:cache => RestGW2.cache)
|
65
|
+
end
|
66
|
+
}
|
67
|
+
|
68
|
+
get '/bank' do
|
69
|
+
@items = gw2.with_item_detail('account/bank')
|
70
|
+
render 'bank'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
Server = Jellyfish::Builder.app do
|
75
|
+
use Rack::CommonLogger
|
76
|
+
use Rack::Chunked
|
77
|
+
use Rack::ContentLength
|
78
|
+
use Rack::Deflater
|
79
|
+
use Rack::ContentType, 'text/html; charset=utf-8'
|
80
|
+
|
81
|
+
map '/assets' do
|
82
|
+
run Rack::Directory.new('public')
|
83
|
+
end
|
84
|
+
|
85
|
+
map '/' do
|
86
|
+
run ServerCore.new
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-TW">
|
4
|
+
<head profile="http://www.w3.org/2005/10/profile">
|
5
|
+
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
|
6
|
+
<meta name="description" content="godfat.org"/>
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
8
|
+
<title>GW2 Bank</title>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<ul>
|
12
|
+
<% @items.each do |item| %>
|
13
|
+
<li>
|
14
|
+
<% if item %>
|
15
|
+
<img src="<%= item['icon'] %>" style="width:64px; height:64px"
|
16
|
+
title="<%= item_title(item) %>"/>
|
17
|
+
(<%= item['count'] %>) <%= item['name'] %>
|
18
|
+
<% else %>
|
19
|
+
N/A
|
20
|
+
<% end %>
|
21
|
+
</li>
|
22
|
+
<% end %>
|
23
|
+
</ul>
|
24
|
+
</body>
|
25
|
+
</html>
|
data/rest-gw2.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: rest-gw2 0.1.0 ruby lib
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "rest-gw2"
|
6
|
+
s.version = "0.1.0"
|
7
|
+
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib"]
|
10
|
+
s.authors = ["Lin Jen-Shin (godfat)"]
|
11
|
+
s.date = "2015-11-14"
|
12
|
+
s.description = "A very simple [Guild Wars 2 API](https://wiki.guildwars2.com/wiki/API:Main)\nclient built with [rest-core](https://github.com/godfat/rest-core).\n\nThere's also a bundled web application showing your items, serving as an\nexample using the client."
|
13
|
+
s.email = ["godfat (XD) godfat.org"]
|
14
|
+
s.files = [
|
15
|
+
".gitignore",
|
16
|
+
".gitmodules",
|
17
|
+
"README.md",
|
18
|
+
"Rakefile",
|
19
|
+
"config.ru",
|
20
|
+
"lib/rest-gw2.rb",
|
21
|
+
"lib/rest-gw2/client.rb",
|
22
|
+
"lib/rest-gw2/server.rb",
|
23
|
+
"lib/rest-gw2/view/bank.erb",
|
24
|
+
"rest-gw2.gemspec",
|
25
|
+
"task/README.md",
|
26
|
+
"task/gemgem.rb"]
|
27
|
+
s.homepage = "https://github.com/godfat/rest-gw2"
|
28
|
+
s.licenses = ["Apache License 2.0"]
|
29
|
+
s.rubygems_version = "2.5.0"
|
30
|
+
s.summary = "A very simple [Guild Wars 2 API](https://wiki.guildwars2.com/wiki/API:Main)"
|
31
|
+
|
32
|
+
if s.respond_to? :specification_version then
|
33
|
+
s.specification_version = 4
|
34
|
+
|
35
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
36
|
+
s.add_runtime_dependency(%q<rest-core>, [">= 0"])
|
37
|
+
else
|
38
|
+
s.add_dependency(%q<rest-core>, [">= 0"])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
s.add_dependency(%q<rest-core>, [">= 0"])
|
42
|
+
end
|
43
|
+
end
|
data/task/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Gemgem
|
2
|
+
|
3
|
+
## DESCRIPTION:
|
4
|
+
|
5
|
+
Provided tasks:
|
6
|
+
|
7
|
+
rake clean # Remove ignored files
|
8
|
+
rake gem:build # Build gem
|
9
|
+
rake gem:install # Install gem
|
10
|
+
rake gem:release # Release gem
|
11
|
+
rake gem:spec # Generate gemspec
|
12
|
+
rake test # Run tests in memory
|
13
|
+
|
14
|
+
## REQUIREMENTS:
|
15
|
+
|
16
|
+
* Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
|
17
|
+
|
18
|
+
## INSTALLATION:
|
19
|
+
|
20
|
+
git submodule add git://github.com/godfat/gemgem.git task
|
21
|
+
|
22
|
+
And in Rakefile:
|
23
|
+
|
24
|
+
``` ruby
|
25
|
+
begin
|
26
|
+
require "#{dir = File.dirname(__FILE__)}/task/gemgem"
|
27
|
+
rescue LoadError
|
28
|
+
sh 'git submodule update --init'
|
29
|
+
exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
|
30
|
+
end
|
31
|
+
|
32
|
+
Gemgem.init(dir) do |s|
|
33
|
+
s.name = 'your-gem'
|
34
|
+
s.version = '0.1.0'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
## LICENSE:
|
39
|
+
|
40
|
+
Apache License 2.0
|
41
|
+
|
42
|
+
Copyright (c) 2011-2013, Lin Jen-Shin (godfat)
|
43
|
+
|
44
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
45
|
+
you may not use this file except in compliance with the License.
|
46
|
+
You may obtain a copy of the License at
|
47
|
+
|
48
|
+
<http://www.apache.org/licenses/LICENSE-2.0>
|
49
|
+
|
50
|
+
Unless required by applicable law or agreed to in writing, software
|
51
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
52
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
53
|
+
See the License for the specific language governing permissions and
|
54
|
+
limitations under the License.
|
data/task/gemgem.rb
ADDED
@@ -0,0 +1,316 @@
|
|
1
|
+
|
2
|
+
module Gemgem
|
3
|
+
class << self
|
4
|
+
attr_accessor :dir, :spec, :spec_create
|
5
|
+
end
|
6
|
+
|
7
|
+
module_function
|
8
|
+
def gem_tag ; "#{spec.name}-#{spec.version}" ; end
|
9
|
+
def gem_path ; "#{pkg_dir}/#{gem_tag}.gem" ; end
|
10
|
+
def spec_path ; "#{dir}/#{spec.name}.gemspec" ; end
|
11
|
+
def pkg_dir ; "#{dir}/pkg" ; end
|
12
|
+
def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
|
13
|
+
|
14
|
+
def init dir, &block
|
15
|
+
self.dir = dir
|
16
|
+
$LOAD_PATH.unshift("#{dir}/lib")
|
17
|
+
ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
|
18
|
+
ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
|
19
|
+
self.spec_create = block
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
spec = Gem::Specification.new do |s|
|
24
|
+
s.authors = ['Lin Jen-Shin (godfat)']
|
25
|
+
s.email = ['godfat (XD) godfat.org']
|
26
|
+
|
27
|
+
s.description = description.join
|
28
|
+
s.summary = description.first
|
29
|
+
s.license = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
|
30
|
+
|
31
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
32
|
+
s.files = gem_files
|
33
|
+
s.test_files = test_files
|
34
|
+
s.executables = bin_files
|
35
|
+
end
|
36
|
+
spec_create.call(spec)
|
37
|
+
spec.homepage ||= "https://github.com/godfat/#{spec.name}"
|
38
|
+
self.spec = spec
|
39
|
+
end
|
40
|
+
|
41
|
+
def gem_install
|
42
|
+
require 'rubygems/commands/install_command'
|
43
|
+
# read ~/.gemrc
|
44
|
+
Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
|
45
|
+
Gem::Command.extra_args = Gem.configuration[:gem]
|
46
|
+
|
47
|
+
# setup install options
|
48
|
+
cmd = Gem::Commands::InstallCommand.new
|
49
|
+
cmd.handle_options([])
|
50
|
+
|
51
|
+
# install
|
52
|
+
install = Gem::Installer.new(gem_path, cmd.options)
|
53
|
+
install.install
|
54
|
+
puts "\e[35mGem installed: \e[33m#{strip_path(install.gem_dir)}\e[0m"
|
55
|
+
end
|
56
|
+
|
57
|
+
def gem_spec
|
58
|
+
create
|
59
|
+
write
|
60
|
+
end
|
61
|
+
|
62
|
+
def gem_build
|
63
|
+
require 'fileutils'
|
64
|
+
require 'rubygems/package'
|
65
|
+
gem = nil
|
66
|
+
Dir.chdir(dir) do
|
67
|
+
gem = Gem::Package.build(Gem::Specification.load(spec_path))
|
68
|
+
FileUtils.mkdir_p(pkg_dir)
|
69
|
+
FileUtils.mv(gem, pkg_dir) # gem is relative path, but might be ok
|
70
|
+
end
|
71
|
+
puts "\e[35mGem built: \e[33m#{strip_path("#{pkg_dir}/#{gem}")}\e[0m"
|
72
|
+
end
|
73
|
+
|
74
|
+
def gem_release
|
75
|
+
sh_git('tag', gem_tag)
|
76
|
+
sh_git('push')
|
77
|
+
sh_git('push', '--tags')
|
78
|
+
sh_gem('push', gem_path)
|
79
|
+
end
|
80
|
+
|
81
|
+
def gem_check
|
82
|
+
unless git('status', '--porcelain').empty?
|
83
|
+
puts("\e[35mWorking copy is not clean.\e[0m")
|
84
|
+
exit(3)
|
85
|
+
end
|
86
|
+
|
87
|
+
ver = spec.version.to_s
|
88
|
+
|
89
|
+
if ENV['VERSION'].nil?
|
90
|
+
puts("\e[35mExpected " \
|
91
|
+
"\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
|
92
|
+
exit(1)
|
93
|
+
|
94
|
+
elsif ENV['VERSION'] != ver
|
95
|
+
puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
|
96
|
+
"\e[35mbut got\n " \
|
97
|
+
"\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
|
98
|
+
exit(2)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test
|
103
|
+
return if test_files.empty?
|
104
|
+
|
105
|
+
if ENV['COV'] || ENV['CI']
|
106
|
+
require 'simplecov'
|
107
|
+
if ENV['CI']
|
108
|
+
begin
|
109
|
+
require 'coveralls'
|
110
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
111
|
+
rescue LoadError => e
|
112
|
+
puts "Cannot load coveralls, skip: #{e}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
SimpleCov.start do
|
116
|
+
add_filter('test/')
|
117
|
+
add_filter('test.rb')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
test_files.each{ |file| require "#{dir}/#{file[0..-4]}" }
|
122
|
+
end
|
123
|
+
|
124
|
+
def clean
|
125
|
+
return if ignored_files.empty?
|
126
|
+
|
127
|
+
require 'fileutils'
|
128
|
+
trash = File.expand_path("~/.Trash/#{spec.name}")
|
129
|
+
puts "Move the following files into: \e[35m#{strip_path(trash)}\e[33m"
|
130
|
+
|
131
|
+
ignored_files.each do |file|
|
132
|
+
from = "#{dir}/#{file}"
|
133
|
+
to = "#{trash}/#{File.dirname(file)}"
|
134
|
+
puts strip_path(from)
|
135
|
+
|
136
|
+
FileUtils.mkdir_p(to)
|
137
|
+
FileUtils.mv(from, to)
|
138
|
+
end
|
139
|
+
|
140
|
+
print "\e[0m"
|
141
|
+
end
|
142
|
+
|
143
|
+
def write
|
144
|
+
File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
|
145
|
+
end
|
146
|
+
|
147
|
+
def split_lines ruby
|
148
|
+
ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
|
149
|
+
if $2.index(',')
|
150
|
+
"#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
|
151
|
+
else
|
152
|
+
s
|
153
|
+
end
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
def strip_path path
|
158
|
+
strip_home_path(strip_cwd_path(path))
|
159
|
+
end
|
160
|
+
|
161
|
+
def strip_home_path path
|
162
|
+
path.sub(ENV['HOME'], '~')
|
163
|
+
end
|
164
|
+
|
165
|
+
def strip_cwd_path path
|
166
|
+
path.sub(Dir.pwd, '.')
|
167
|
+
end
|
168
|
+
|
169
|
+
def git *args
|
170
|
+
`git --git-dir=#{dir}/.git #{args.join(' ')}`
|
171
|
+
end
|
172
|
+
|
173
|
+
def sh_git *args
|
174
|
+
Rake.sh('git', "--git-dir=#{dir}/.git", *args)
|
175
|
+
end
|
176
|
+
|
177
|
+
def sh_gem *args
|
178
|
+
Rake.sh(Gem.ruby, '-S', 'gem', *args)
|
179
|
+
end
|
180
|
+
|
181
|
+
def glob path=dir
|
182
|
+
Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
|
183
|
+
end
|
184
|
+
|
185
|
+
def readme
|
186
|
+
@readme ||=
|
187
|
+
if (path = "#{Gemgem.dir}/README.md") && File.exist?(path)
|
188
|
+
ps = "##{File.read(path)}".
|
189
|
+
scan(/((#+)[^\n]+\n\n.+?(?=(\n\n\2[^#\n]+\n)|\Z))/m).map(&:first)
|
190
|
+
ps.inject('HEADER' => ps.first){ |r, s, i|
|
191
|
+
r[s[/\w+/]] = s
|
192
|
+
r
|
193
|
+
}
|
194
|
+
else
|
195
|
+
{}
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def description
|
200
|
+
# JRuby String#lines is returning an enumerator
|
201
|
+
@description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
|
202
|
+
end
|
203
|
+
|
204
|
+
def all_files
|
205
|
+
@all_files ||= fold_files(glob).sort
|
206
|
+
end
|
207
|
+
|
208
|
+
def fold_files files
|
209
|
+
files.inject([]){ |r, path|
|
210
|
+
if File.file?(path) && path !~ %r{/\.git(/|$)} &&
|
211
|
+
(rpath = path[%r{^#{escaped_dir}/(.*$)}, 1])
|
212
|
+
r << rpath
|
213
|
+
elsif File.symlink?(path) # walk into symlinks...
|
214
|
+
r.concat(fold_files(glob(File.expand_path(path,
|
215
|
+
File.readlink(path)))))
|
216
|
+
else
|
217
|
+
r
|
218
|
+
end
|
219
|
+
}
|
220
|
+
end
|
221
|
+
|
222
|
+
def gem_files
|
223
|
+
@gem_files ||= all_files.reject{ |f|
|
224
|
+
f =~ ignored_pattern && !git_files.include?(f)
|
225
|
+
}
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_files
|
229
|
+
@test_files ||= gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
|
230
|
+
end
|
231
|
+
|
232
|
+
def bin_files
|
233
|
+
@bin_files ||= gem_files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
234
|
+
end
|
235
|
+
|
236
|
+
def git_files
|
237
|
+
@git_files ||= if File.exist?("#{dir}/.git")
|
238
|
+
git('ls-files').split("\n")
|
239
|
+
else
|
240
|
+
[]
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def ignored_files
|
245
|
+
@ignored_files ||= all_files.grep(ignored_pattern)
|
246
|
+
end
|
247
|
+
|
248
|
+
def ignored_pattern
|
249
|
+
@ignored_pattern ||= if gitignore.empty?
|
250
|
+
/^$/
|
251
|
+
else
|
252
|
+
Regexp.new(expand_patterns(gitignore).join('|'))
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def expand_patterns pathes
|
257
|
+
# http://git-scm.com/docs/gitignore
|
258
|
+
pathes.flat_map{ |path|
|
259
|
+
# we didn't implement negative pattern for now
|
260
|
+
Regexp.escape(path).sub(%r{^/}, '^').gsub(/\\\*/, '[^/]*')
|
261
|
+
}
|
262
|
+
end
|
263
|
+
|
264
|
+
def gitignore
|
265
|
+
@gitignore ||= if File.exist?(path = "#{dir}/.gitignore")
|
266
|
+
File.read(path).lines.
|
267
|
+
reject{ |l| l == /^\s*(#|\s+$)/ }.map(&:strip)
|
268
|
+
else
|
269
|
+
[]
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
namespace :gem do
|
275
|
+
|
276
|
+
desc 'Install gem'
|
277
|
+
task :install => [:build] do
|
278
|
+
Gemgem.gem_install
|
279
|
+
end
|
280
|
+
|
281
|
+
desc 'Build gem'
|
282
|
+
task :build => [:spec] do
|
283
|
+
Gemgem.gem_build
|
284
|
+
end
|
285
|
+
|
286
|
+
desc 'Generate gemspec'
|
287
|
+
task :spec do
|
288
|
+
Gemgem.gem_spec
|
289
|
+
end
|
290
|
+
|
291
|
+
desc 'Release gem'
|
292
|
+
task :release => [:spec, :check, :build] do
|
293
|
+
Gemgem.gem_release
|
294
|
+
end
|
295
|
+
|
296
|
+
task :check do
|
297
|
+
Gemgem.gem_check
|
298
|
+
end
|
299
|
+
|
300
|
+
end # of gem namespace
|
301
|
+
|
302
|
+
desc 'Run tests'
|
303
|
+
task :test do
|
304
|
+
Gemgem.test
|
305
|
+
end
|
306
|
+
|
307
|
+
desc 'Trash ignored files'
|
308
|
+
task :clean => ['gem:spec'] do
|
309
|
+
Gemgem.clean
|
310
|
+
end
|
311
|
+
|
312
|
+
task :default do
|
313
|
+
# Is there a reliable way to do this in the current process?
|
314
|
+
# It failed miserably before between Rake versions...
|
315
|
+
exec "#{Gem.ruby} -S #{$PROGRAM_NAME} -f #{Rake.application.rakefile} -T"
|
316
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rest-gw2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lin Jen-Shin (godfat)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: |-
|
28
|
+
A very simple [Guild Wars 2 API](https://wiki.guildwars2.com/wiki/API:Main)
|
29
|
+
client built with [rest-core](https://github.com/godfat/rest-core).
|
30
|
+
|
31
|
+
There's also a bundled web application showing your items, serving as an
|
32
|
+
example using the client.
|
33
|
+
email:
|
34
|
+
- godfat (XD) godfat.org
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- ".gitignore"
|
40
|
+
- ".gitmodules"
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- config.ru
|
44
|
+
- lib/rest-gw2.rb
|
45
|
+
- lib/rest-gw2/client.rb
|
46
|
+
- lib/rest-gw2/server.rb
|
47
|
+
- lib/rest-gw2/view/bank.erb
|
48
|
+
- rest-gw2.gemspec
|
49
|
+
- task/README.md
|
50
|
+
- task/gemgem.rb
|
51
|
+
homepage: https://github.com/godfat/rest-gw2
|
52
|
+
licenses:
|
53
|
+
- Apache License 2.0
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.5.0
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: A very simple [Guild Wars 2 API](https://wiki.guildwars2.com/wiki/API:Main)
|
75
|
+
test_files: []
|