mingle-api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3b92dc4e3ee97b73989ae149169b01d557ca851
4
- data.tar.gz: c30f9f566d55bba6ae60813868e699b973bd9a33
3
+ metadata.gz: ae66c339e419d41ddcc88a990a87067c92c73bbd
4
+ data.tar.gz: 689645f008b9cb5c7605c9efe606d9687f3f084f
5
5
  SHA512:
6
- metadata.gz: db70cbc86a8adf54a2ee2d67d21a88d2491b971e1a3253f0532de99c9731a3f29046f34beaf7a7e71d45e6398cd1f3abf267da88c41d64cc033c18dfdde83ded
7
- data.tar.gz: b414e86ab1d521cf99c32f9d51cb87cd85f78737cbc0fa833f6e2afb8ffe77a2d3f9088d2e134969f836f94993a24159aa1f1e1b586872030ae1973ab7dacc4f
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
- mingle = Mingle.new('site-name', hmac: [username, secret_key])
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 = Mingle.new('site-name', basic_auth: [username, password])
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 = Mingle.new('https://your-mingle-site-url', hmac: [username, secret_key])
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/[my-github-username]/mingle-api/fork )
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
@@ -17,4 +17,5 @@
17
17
  * MQL execution
18
18
  * Favorite APIs
19
19
  * User APIs
20
- * option to turn off OpenSSL::SSL::VERIFY_NONE
20
+ * option to turn off OpenSSL::SSL::VERIFY_NONE
21
+ * fix mingle-api gem require problem
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
@@ -3,7 +3,7 @@ require 'net/https'
3
3
  require 'net/http/post/multipart'
4
4
  require 'api-auth'
5
5
 
6
- class Mingle
6
+ class MingleAPI
7
7
  class Http
8
8
  class Error < StandardError
9
9
  def initialize(request_class, url, response)
@@ -1,4 +1,4 @@
1
- class Mingle
1
+ class MingleAPI
2
2
  class Macro
3
3
  def text(node, css)
4
4
  if ret = node.at_css(css)
@@ -0,0 +1,3 @@
1
+ class MingleAPI
2
+ VERSION = "0.0.3"
3
+ 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/api/version'
4
+ require 'mingle-api/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "mingle-api"
8
- spec.version = Mingle::Api::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.}
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class MingleTest < Minitest::Test
3
+ class MingleAPITest < Minitest::Test
4
4
  def test_projects
5
5
  mingle = create_basic_auth_mingle
6
6
  first_proj = mingle.projects.find{|proj| proj.identifier == 'your_first_project'}
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
- Mingle.new(ENV['MINGLE_SITE'], basic_auth: [ENV['MINGLE_USERNAME'], ENV['MINGLE_PASSWORD']])
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
- Mingle.new(ENV['MINGLE_SITE'], hmac: [ENV['MINGLE_USERNAME'], ENV['MINGLE_SECRET_KEY']])
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.2
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-18 00:00:00.000000000 Z
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/mingle/api.rb
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/mingle_test.rb
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/mingle_test.rb
149
+ - test/mingle_api_test.rb
149
150
  - test/test_helper.rb
data/lib/mingle/api.rb DELETED
@@ -1,7 +0,0 @@
1
- require "mingle/api/version"
2
-
3
- module Mingle
4
- module Api
5
- # Your code goes here...
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- module Mingle
2
- module Api
3
- VERSION = "0.0.2"
4
- end
5
- end