mingle-api 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +5 -4
- data/TODO +2 -1
- data/lib/mingle-api.rb +134 -0
- data/lib/{mingle → mingle-api}/http.rb +1 -1
- data/lib/{mingle → mingle-api}/macro.rb +1 -1
- data/lib/mingle-api/version.rb +3 -0
- data/lib/mingle_api.rb +1 -0
- data/mingle-api.gemspec +2 -2
- data/test/{mingle_test.rb → mingle_api_test.rb} +1 -1
- data/test/test_helper.rb +3 -3
- metadata +9 -8
- data/lib/mingle/api.rb +0 -7
- data/lib/mingle/api/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae66c339e419d41ddcc88a990a87067c92c73bbd
|
4
|
+
data.tar.gz: 689645f008b9cb5c7605c9efe606d9687f3f084f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 524be8951cb7b421f55adf7950e35b68d071f3b3d935605d28073d4606eb7b1e8e26e1bddc2655a7db3c670c7849a4fcb5ea007884d4fa666cd99a93c35534b1
|
7
|
+
data.tar.gz: 4e81b733c085b9f6b1f9b44c27d1353871239d6a204ffac9d3a0f407f938be3d438578e5d1d528cc095d3e29985318d0d76dbb7b25473a3ced569ad10092cd89
|
data/README.md
CHANGED
@@ -25,15 +25,16 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
### Initialize with HMac Auth for SaaS Mingle site
|
27
27
|
|
28
|
-
|
28
|
+
require 'mingle-api'
|
29
|
+
mingle = MingleAPI.new('site-name', hmac: [username, secret_key])
|
29
30
|
|
30
31
|
### Initialize with Basic Auth for SaaS Mingle site
|
31
32
|
|
32
|
-
mingle =
|
33
|
+
mingle = MingleAPI.new('site-name', basic_auth: [username, password])
|
33
34
|
|
34
35
|
### Initialize with HMac for onsite Mingle site
|
35
36
|
|
36
|
-
mingle =
|
37
|
+
mingle = MingleAPI.new('https://your-mingle-site-url', hmac: [username, secret_key])
|
37
38
|
|
38
39
|
### Get all projects
|
39
40
|
|
@@ -86,7 +87,7 @@ See .rbenv-vars file for environment variables need for test.
|
|
86
87
|
|
87
88
|
## Contributing
|
88
89
|
|
89
|
-
1. Fork it ( https://github.com/
|
90
|
+
1. Fork it ( https://github.com/ThoughtWorksStudios/mingle-api/fork )
|
90
91
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
91
92
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
92
93
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/TODO
CHANGED
data/lib/mingle-api.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
require 'mingle-api/http'
|
5
|
+
require 'mingle-api/macro'
|
6
|
+
require "mingle-api/version"
|
7
|
+
|
8
|
+
class MingleAPI
|
9
|
+
|
10
|
+
attr_reader :site
|
11
|
+
|
12
|
+
PROJECT = [:name, :identifier, :description]
|
13
|
+
CARD = [:name, :description,
|
14
|
+
{
|
15
|
+
"card_type name" => :type,
|
16
|
+
'properties property' => lambda do |node|
|
17
|
+
name = text(node, 'name')
|
18
|
+
value = case node[:type_description]
|
19
|
+
when /team list/
|
20
|
+
text(node, 'value login')
|
21
|
+
else
|
22
|
+
text(node, 'value')
|
23
|
+
end
|
24
|
+
[name.downcase, value]
|
25
|
+
end
|
26
|
+
}
|
27
|
+
]
|
28
|
+
|
29
|
+
def initialize(site, credentials)
|
30
|
+
@site, @http = site, Http.new(credentials)
|
31
|
+
end
|
32
|
+
|
33
|
+
def projects
|
34
|
+
list(fetch(:projects), PROJECT)
|
35
|
+
end
|
36
|
+
|
37
|
+
def project(identifier)
|
38
|
+
ostruct(fetch(:projects, identifier), PROJECT)
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_project(name, options={})
|
42
|
+
identifier = name.downcase.gsub(/[^a-z0-9_]/, '_')
|
43
|
+
@http.post(v2(:projects), {
|
44
|
+
"project[name]" => name,
|
45
|
+
"project[identifier]" => identifier,
|
46
|
+
"project[description]" => options[:description],
|
47
|
+
"project[template]" => false,
|
48
|
+
"template_name" => options[:template] ? "yml_#{options[:template]}_template" : nil
|
49
|
+
})
|
50
|
+
OpenStruct.new(:identifier => identifier, :name => name, :url => url('projects', identifier))
|
51
|
+
end
|
52
|
+
|
53
|
+
def cards(project)
|
54
|
+
list(fetch(:projects, project_identifier(project), :cards), CARD)
|
55
|
+
end
|
56
|
+
|
57
|
+
def card(project, number)
|
58
|
+
ostruct(fetch(:projects, project_identifier(project), :cards, number), CARD)
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_card(project, attrs)
|
62
|
+
params = [
|
63
|
+
["card[name]", attrs[:name]],
|
64
|
+
["card[card_type_name]", attrs[:type]],
|
65
|
+
["card[description]", attrs[:description]]
|
66
|
+
]
|
67
|
+
Array(attrs[:attachments]).each_with_index do |attachment, i|
|
68
|
+
path, content_type = attachment
|
69
|
+
params << ["attachments[#{i}]", UploadIO.new(File.new(path), content_type, File.basename(path))]
|
70
|
+
end
|
71
|
+
Array(attrs[:properties]).each_with_index do |prop, i|
|
72
|
+
name, value = prop
|
73
|
+
params << ["card[properties][][name]", name]
|
74
|
+
params << ["card[properties][][value]", value]
|
75
|
+
end
|
76
|
+
resp = @http.post(v2(:projects, project_identifier(project), :cards), params)
|
77
|
+
number = resp[2]["location"].split("/").last.split('.').first
|
78
|
+
OpenStruct.new(:number => number, :url => url('projects', project_identifier(project), 'cards', number))
|
79
|
+
end
|
80
|
+
|
81
|
+
def site_api_url
|
82
|
+
gen_site_url(api_host)
|
83
|
+
end
|
84
|
+
|
85
|
+
def site_url
|
86
|
+
gen_site_url(host)
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
def project_identifier(proj)
|
91
|
+
proj.respond_to?(:identifier) ? proj.identifier : proj.to_s
|
92
|
+
end
|
93
|
+
|
94
|
+
def url(*parts)
|
95
|
+
File.join(site_url, *parts)
|
96
|
+
end
|
97
|
+
|
98
|
+
def api_host
|
99
|
+
'mingle-api.thoughtworks.com' || ENV['MINGLE_API_HOST']
|
100
|
+
end
|
101
|
+
|
102
|
+
def host
|
103
|
+
'mingle.thoughtworks.com' || ENV['MINGLE_HOST']
|
104
|
+
end
|
105
|
+
|
106
|
+
def fetch(*resources)
|
107
|
+
dom(@http.get(v2(*resources))[1]).root
|
108
|
+
end
|
109
|
+
|
110
|
+
def list(dom, attrs)
|
111
|
+
dom.children.map do |child|
|
112
|
+
ostruct(child, attrs)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def ostruct(node, attrs)
|
117
|
+
macro = Macro.new
|
118
|
+
OpenStruct.new(Hash[*macro.apply(node, attrs)])
|
119
|
+
end
|
120
|
+
|
121
|
+
def dom(xml)
|
122
|
+
Nokogiri::XML(xml) do |config|
|
123
|
+
config.options = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::STRICT | Nokogiri::XML::ParseOptions::NONET
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def v2(*parts)
|
128
|
+
[File.join(site_api_url, 'api/v2', *parts.map(&:to_s)), 'xml'].join('.')
|
129
|
+
end
|
130
|
+
|
131
|
+
def gen_site_url(h)
|
132
|
+
site =~ /^http/i ? site : "https://#{site}.#{h}"
|
133
|
+
end
|
134
|
+
end
|
data/lib/mingle_api.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'mingle-api'
|
data/mingle-api.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'mingle
|
4
|
+
require 'mingle-api/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "mingle-api"
|
8
|
-
spec.version =
|
8
|
+
spec.version = MingleAPI::VERSION
|
9
9
|
spec.authors = ["Xiao Li"]
|
10
10
|
spec.email = ["swing1979@gmail.com"]
|
11
11
|
spec.summary = %q{[The Mingle API gem provides simple interface for you to build ruby application talks to Mingle.}
|
data/test/test_helper.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
|
-
require 'mingle'
|
2
|
+
require 'mingle-api'
|
3
3
|
require "minitest/autorun"
|
4
4
|
|
5
5
|
def create_basic_auth_mingle
|
6
|
-
|
6
|
+
MingleAPI.new(ENV['MINGLE_SITE'], basic_auth: [ENV['MINGLE_USERNAME'], ENV['MINGLE_PASSWORD']])
|
7
7
|
end
|
8
8
|
|
9
9
|
def create_hmac_auth_mingle
|
10
|
-
|
10
|
+
MingleAPI.new(ENV['MINGLE_SITE'], hmac: [ENV['MINGLE_USERNAME'], ENV['MINGLE_SECRET_KEY']])
|
11
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mingle-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xiao Li
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: api-auth
|
@@ -111,13 +111,14 @@ files:
|
|
111
111
|
- README.md
|
112
112
|
- Rakefile
|
113
113
|
- TODO
|
114
|
+
- lib/mingle-api.rb
|
115
|
+
- lib/mingle-api/http.rb
|
116
|
+
- lib/mingle-api/macro.rb
|
117
|
+
- lib/mingle-api/version.rb
|
114
118
|
- lib/mingle.rb
|
115
|
-
- lib/
|
116
|
-
- lib/mingle/api/version.rb
|
117
|
-
- lib/mingle/http.rb
|
118
|
-
- lib/mingle/macro.rb
|
119
|
+
- lib/mingle_api.rb
|
119
120
|
- mingle-api.gemspec
|
120
|
-
- test/
|
121
|
+
- test/mingle_api_test.rb
|
121
122
|
- test/test_helper.rb
|
122
123
|
homepage: https://github.com/ThoughtWorksStudios/mingle-api
|
123
124
|
licenses:
|
@@ -145,5 +146,5 @@ specification_version: 4
|
|
145
146
|
summary: "[The Mingle API gem provides simple interface for you to build ruby application
|
146
147
|
talks to Mingle."
|
147
148
|
test_files:
|
148
|
-
- test/
|
149
|
+
- test/mingle_api_test.rb
|
149
150
|
- test/test_helper.rb
|
data/lib/mingle/api.rb
DELETED