megam_scmmanager 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 49399c40301ccad6c42fa7bfd99fb41332b5e06c
4
+ data.tar.gz: 95b3ef771016612ce61d3b274d14dc7449eb1592
5
+ SHA512:
6
+ metadata.gz: a75391c2d92476a51999604b3fa8287d61b46db0a5c9fc8ac527ec6efbe0530c57769ba70079e58c560107e2ed7ac868c130ab646dfc5fd48652a26925d0ccae
7
+ data.tar.gz: cd5f666f8246d93b564e653a106748b1e118b1fe4c5715caa38d424c5a1408a8a70d563270b2e44f1ece994111aea655c7dd65b2b737960916dee221a67d5d16
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>megam_scm_api</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ <nature>com.aptana.ruby.core.rubynature</nature>
11
+ </natures>
12
+ </projectDescription>
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ notifications:
4
+ email:
5
+ recipients:
6
+ - rajthilak@megam.co.in
7
+
8
+ rvm:
9
+ - 2.1.0
10
+
11
+ script: bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in megam_api.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
34
+ available under the License, as indicated by a copyright notice that is included
35
+ in or attached to the work (an example is provided in the Appendix below).
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
+ by the copyright owner or by an individual or Legal Entity authorized to submit
48
+ on behalf of the copyright owner. For the purposes of this definition,
49
+ "submitted" means any form of electronic, verbal, or written communication sent
50
+ to the Licensor or its representatives, including but not limited to
51
+ communication on electronic mailing lists, source code control systems, and
52
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
53
+ the purpose of discussing and improving the Work, but excluding communication
54
+ that is conspicuously marked or otherwise designated in writing by the copyright
55
+ owner as "Not a Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License.
62
+
63
+ Subject to the terms and conditions of this License, each Contributor hereby
64
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
66
+ publicly display, publicly perform, sublicense, and distribute the Work and such
67
+ Derivative Works in Source or Object form.
68
+
69
+ 3. Grant of Patent License.
70
+
71
+ Subject to the terms and conditions of this License, each Contributor hereby
72
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73
+ irrevocable (except as stated in this section) patent license to make, have
74
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75
+ such license applies only to those patent claims licensable by such Contributor
76
+ that are necessarily infringed by their Contribution(s) alone or by combination
77
+ of their Contribution(s) with the Work to which such Contribution(s) was
78
+ submitted. If You institute patent litigation against any entity (including a
79
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80
+ Contribution incorporated within the Work constitutes direct or contributory
81
+ patent infringement, then any patent licenses granted to You under this License
82
+ for that Work shall terminate as of the date such litigation is filed.
83
+
84
+ 4. Redistribution.
85
+
86
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
87
+ in any medium, with or without modifications, and in Source or Object form,
88
+ provided that You meet the following conditions:
89
+
90
+ You must give any other recipients of the Work or Derivative Works a copy of
91
+ this License; and
92
+ You must cause any modified files to carry prominent notices stating that You
93
+ changed the files; and
94
+ You must retain, in the Source form of any Derivative Works that You distribute,
95
+ all copyright, patent, trademark, and attribution notices from the Source form
96
+ of the Work, excluding those notices that do not pertain to any part of the
97
+ Derivative Works; and
98
+ If the Work includes a "NOTICE" text file as part of its distribution, then any
99
+ Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents of
106
+ the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+ You may add Your own copyright statement to Your modifications and may provide
112
+ additional or different license terms and conditions for use, reproduction, or
113
+ distribution of Your modifications, or for any such Derivative Works as a whole,
114
+ provided Your use, reproduction, and distribution of the Work otherwise complies
115
+ with the conditions stated in this License.
116
+
117
+ 5. Submission of Contributions.
118
+
119
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
120
+ for inclusion in the Work by You to the Licensor shall be under the terms and
121
+ conditions of this License, without any additional terms or conditions.
122
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of
123
+ any separate license agreement you may have executed with Licensor regarding
124
+ such Contributions.
125
+
126
+ 6. Trademarks.
127
+
128
+ This License does not grant permission to use the trade names, trademarks,
129
+ service marks, or product names of the Licensor, except as required for
130
+ reasonable and customary use in describing the origin of the Work and
131
+ reproducing the content of the NOTICE file.
132
+
133
+ 7. Disclaimer of Warranty.
134
+
135
+ Unless required by applicable law or agreed to in writing, Licensor provides the
136
+ Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138
+ including, without limitation, any warranties or conditions of TITLE,
139
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140
+ solely responsible for determining the appropriateness of using or
141
+ redistributing the Work and assume any risks associated with Your exercise of
142
+ permissions under this License.
143
+
144
+ 8. Limitation of Liability.
145
+
146
+ In no event and under no legal theory, whether in tort (including negligence),
147
+ contract, or otherwise, unless required by applicable law (such as deliberate
148
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
149
+ liable to You for damages, including any direct, indirect, special, incidental,
150
+ or consequential damages of any character arising as a result of this License or
151
+ out of the use or inability to use the Work (including but not limited to
152
+ damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153
+ any and all other commercial damages or losses), even if such Contributor has
154
+ been advised of the possibility of such damages.
155
+
156
+ 9. Accepting Warranty or Additional Liability.
157
+
158
+ While redistributing the Work or Derivative Works thereof, You may choose to
159
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160
+ other liability obligations and/or rights consistent with this License. However,
161
+ in accepting such obligations, You may act only on Your own behalf and on Your
162
+ sole responsibility, not on behalf of any other Contributor, and only if You
163
+ agree to indemnify, defend, and hold each Contributor harmless for any liability
164
+ incurred by, or claims asserted against, such Contributor by reason of your
165
+ accepting any such warranty or additional liability.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ APPENDIX: How to apply the Apache License to your work
170
+
171
+ To apply the Apache License to your work, attach the following boilerplate
172
+ notice, with the fields enclosed by brackets "[]" replaced with your own
173
+ identifying information. (Don't include the brackets!) The text should be
174
+ enclosed in the appropriate comment syntax for the file format. We also
175
+ recommend that a file or class name and description of purpose be included on
176
+ the same "printed page" as the copyright notice for easier identification within
177
+ third-party archives.
178
+
179
+ Copyright [yyyy] [name of copyright owner]
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -0,0 +1,47 @@
1
+ Scm manager Ruby Client
2
+ ==================
3
+
4
+ The scm manager ruby cleint which is used to interact with the scm-manager.org
5
+
6
+
7
+ Launching soon. For early access [register at:](http://www.megam.co)
8
+
9
+ Usage
10
+ -----
11
+
12
+ Start by creating a connection to Megam with your credentials:
13
+
14
+ require 'megam_scm_api'
15
+
16
+ megam = Megam::Scm.new
17
+
18
+ Now you can make requests to the api.
19
+
20
+ Requests
21
+ --------
22
+
23
+
24
+
25
+
26
+ # License
27
+
28
+ | | |
29
+ |:---------------------|:-----------------------------------------|
30
+ | **Author:** | Raj Thilak (<rajthilka@megam.co.in>)
31
+ | | Kishorekumar Neelamegam (<nkishore@megam.co.in>)
32
+ | | Thomas Alrin (<alrin@megam.co.in>)
33
+ | **Copyright:** | Copyright (c) 2012-2013 Megam Systems.
34
+ | **License:** | Apache License, Version 2.0
35
+
36
+ Licensed under the Apache License, Version 2.0 (the "License");
37
+ you may not use this file except in compliance with the License.
38
+ You may obtain a copy of the License at
39
+
40
+ http://www.apache.org/licenses/LICENSE-2.0
41
+
42
+ Unless required by applicable law or agreed to in writing, software
43
+ distributed under the License is distributed on an "AS IS" BASIS,
44
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45
+ See the License for the specific language governing permissions and
46
+ limitations under the License.
47
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new do |task|
8
+ task.name = :test
9
+ task.test_files = FileList['test/test*.rb']
10
+ end
@@ -0,0 +1,218 @@
1
+ # Copyright:: Copyright (c) 2012-2013 Megam Systems, Inc.
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Megam
18
+ class ScmmAccount
19
+ def initialize(name=nil, displayName=nil, mail=nil, password=nil)
20
+ @creationDate = nil
21
+ @admin = nil
22
+ @type = nil
23
+ @password = nil
24
+ @name = nil
25
+ @mail = nil
26
+ @displayName = nil
27
+ @lastModified = nil
28
+ @active = nil
29
+ @some_msg = {}
30
+ super(name, displayName, mail, password)
31
+ end
32
+
33
+ #used by resque workers and any other background job
34
+ def account
35
+ self
36
+ end
37
+
38
+ def creationDate(arg=nil)
39
+ if arg != nil
40
+ @creationDate = arg
41
+ else
42
+ @creationDate
43
+ end
44
+ end
45
+
46
+ def admin(arg=nil)
47
+ if arg != nil
48
+ @admin = arg
49
+ else
50
+ @admin
51
+ end
52
+ end
53
+
54
+ def type(arg=nil)
55
+ if arg != nil
56
+ @type = arg
57
+ else
58
+ @type
59
+ end
60
+ end
61
+
62
+ def password(arg=nil)
63
+ if arg != nil
64
+ @password = arg
65
+ else
66
+ @password
67
+ end
68
+ end
69
+
70
+ def name(arg=nil)
71
+ if arg != nil
72
+ @name = arg
73
+ else
74
+ @name
75
+ end
76
+ end
77
+
78
+ def mail(arg=nil)
79
+ if arg != nil
80
+ @mail = arg
81
+ else
82
+ @mail
83
+ end
84
+ end
85
+
86
+ def displayName(arg=nil)
87
+ if arg != nil
88
+ @displayName = arg
89
+ else
90
+ @displayName
91
+ end
92
+ end
93
+
94
+ def lastModified(arg=nil)
95
+ if arg != nil
96
+ @lastModified = arg
97
+ else
98
+ @lastModified
99
+ end
100
+ end
101
+
102
+ def active(arg=nil)
103
+ if arg != nil
104
+ @active = arg
105
+ else
106
+ @active
107
+ end
108
+ end
109
+
110
+ def some_msg(arg=nil)
111
+ if arg != nil
112
+ @some_msg = arg
113
+ else
114
+ @some_msg
115
+ end
116
+ end
117
+
118
+ def error?
119
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
120
+ end
121
+
122
+ # Transform the ruby obj -> to a Hash
123
+ def to_hash
124
+ index_hash = Hash.new
125
+ index_hash["json_claz"] = self.class.name
126
+ index_hash["creationDate"] = creationDate
127
+ index_hash["admin"] = admin
128
+ index_hash["type"] = type
129
+ index_hash["password"] = password
130
+ index_hash["name"] = name
131
+ index_hahs["mail"] = mail
132
+ index_hash["displayName"] = displayName
133
+ index_hash["lastModified"] = lastModified
134
+ index_hash["active"] = active
135
+ index_hash["some_msg"] = some_msg
136
+ index_hash
137
+ end
138
+
139
+ # Serialize this object as a hash: called from JsonCompat.
140
+ # Verify if this called from JsonCompat during testing.
141
+ def to_json(*a)
142
+ for_json.to_json(*a)
143
+ end
144
+
145
+ def for_json
146
+ result = {
147
+ "creationDate" => creationDate,
148
+ "admin" => admin,
149
+ "type" => type,
150
+ "password" => password,
151
+ "name" => name,
152
+ "mail" => mail,
153
+ "displayName" => displayName,
154
+ "lastModified" => lastModified,
155
+ "active" => active
156
+ }
157
+ result
158
+ end
159
+
160
+ # Create a Megam::Account from JSON (used by the backgroud job workers)
161
+ def self.json_create(o)
162
+ acct = new
163
+ acct.creationDate(o["creationDate"]) if o.has_key?("creationDate")
164
+ acct.admin(o["admin"]) if o.has_key?("admin")
165
+ acct.type(o["type"]) if o.has_key?("type")
166
+ acct.password(o["password"]) if o.has_key?("password")
167
+ acct.name(o["name"]) if o.has_key?("name")
168
+ acct.mail(o["mail"]) if o.has_key?("mail")
169
+ acct.displayName(o["displayName"]) if o.has_key?("displayName]")
170
+ acct.lastModified(o["lastModifiec"]) if o.has_key?("lastModified")
171
+ acct.active(o["active"]) if o.has_key?("active")
172
+ acct.some_msg[:code] = o["code"] if o.has_key?("code")
173
+ acct.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
174
+ acct.some_msg[:msg]= o["msg"] if o.has_key?("msg")
175
+ acct.some_msg[:links] = o["links"] if o.has_key?("links")
176
+ acct
177
+ end
178
+
179
+ def self.from_hash(o)
180
+ acct = self.new(o[:name], o[:displayName], o[:mail], o[:password])
181
+ acct.from_hash(o)
182
+ acct
183
+ end
184
+
185
+ def from_hash(o)
186
+ @creationDate = o[:creationDate] if o.has_key?(:creationDate)
187
+ @admin = o[:admin] if o.has_key?(:admin)
188
+ @type = o[:type] if o.has_key?(:type)
189
+ @password = o[:password] if o.has_key?(:password)
190
+ @name = o[:name] if o.has_key?(:name)
191
+ @mail = o[:mail] if o.has_key?(:mail)
192
+ @displayName = o[:displayName] if o.has_key?(:displayName)
193
+ @lastModified = o[:lastModified] if o.has_key?(:lastModified)
194
+ @active = o[:active] if o.has_key?(:active)
195
+ self
196
+ end
197
+
198
+ def self.create(o)
199
+ acct = from_hash(o)
200
+ acct.create
201
+ end
202
+
203
+ # Load a account by email_p
204
+ def self.show(name, displayName, mail, password)
205
+ acct = self.new(name, displayName, mail, password)
206
+ acct.megam_rest.get_accounts(mail)
207
+ end
208
+
209
+ # Create the node via the REST API
210
+ def create
211
+ megam_rest.post_accounts(to_hash)
212
+ end
213
+
214
+ def to_s
215
+ Megam::Stuff.styled_hash(to_hash)
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,57 @@
1
+ # Copyright:: Copyright (c) 2012-2013 Megam Systems, Inc.
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module Megam
17
+ class ScmmRepo
18
+
19
+ # Transform the ruby obj -> to a Hash
20
+ def self.to_hash(response)
21
+ index_hash = []
22
+ i = 0
23
+ config = Nokogiri::XML(response.body)
24
+ config.css("repositories repositories").map do |node|
25
+ node.children.map {|n|
26
+ if n.name == 'url'
27
+ index_hash << n.text.strip
28
+ end
29
+ }
30
+ end
31
+ {:status => response.code, :body => index_hash, :some_msg => response.message }
32
+ end
33
+
34
+
35
+ # Load a account by email_p
36
+ def self.list(username, password)
37
+ #acct = self.new(username, password)
38
+ megams = Megam::Scmmanager.new
39
+ res = megams.get_repos(username, password)
40
+ hash = {}
41
+ if res.code != "200"
42
+ hash = self.error(res)
43
+ else
44
+ hash = self.to_hash(res)
45
+ end
46
+ hash
47
+ end
48
+
49
+ def self.error(response)
50
+ {:status => response.code, :body => "", :some_msg => response.message }
51
+ end
52
+
53
+ def to_s
54
+ Megam::Stuff.styled_hash(to_hash)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,95 @@
1
+ require "time"
2
+ require "uri"
3
+ require "zlib"
4
+ require 'openssl'
5
+ require 'net/http'
6
+
7
+ __LIB_DIR__ = File.expand_path(File.join(File.dirname(__FILE__), ".."))
8
+ unless $LOAD_PATH.include?(__LIB_DIR__)
9
+ $LOAD_PATH.unshift(__LIB_DIR__)
10
+ end
11
+
12
+ require "megam/scmmanager/version"
13
+ require "megam/scmmanager/accounts"
14
+ require "megam/scmmanager/dumpout"
15
+ require "megam/scmmanager/errors"
16
+ require "megam/scmmanager/repos"
17
+ require "megam/core/scmm/scmmrepo"
18
+ require "megam/core/scmm/scmmaccount"
19
+
20
+ module Megam
21
+ class Scmmanager
22
+
23
+ HEADERS = {
24
+ 'Accept' => 'application/json',
25
+ 'Accept-Encoding' => 'gzip',
26
+ 'User-Agent' => "megam-scmmanager/#{Megam::Scmmanager::VERSION}",
27
+ 'X-Ruby-Version' => RUBY_VERSION,
28
+ 'X-Ruby-Platform' => RUBY_PLATFORM
29
+ }
30
+
31
+ OPTIONS = {
32
+ :headers => {},
33
+ :host => 'scm-manager.megam.co',
34
+ :port => '8080',
35
+ :nonblock => false,
36
+ :scheme => 'http'
37
+ }
38
+
39
+ API_REST = "/scmmanager/api/rest"
40
+ AUTH_PATH="/authentication/login"
41
+
42
+ def text
43
+ @text ||= Megam::Dumpout.new(STDOUT, STDERR, STDIN)
44
+ end
45
+
46
+ def last_response
47
+ @last_response
48
+ end
49
+
50
+ # It is assumed that every API call will NOT use an API_KEY/email.
51
+ def initialize(options={})
52
+ @options = OPTIONS.merge(options)
53
+ end
54
+
55
+ def request(params, &block)
56
+ start = Time.now
57
+ puts params
58
+ text.msg "#{text.color("START", :cyan, :bold)}"
59
+ username = params[:username] || ENV['MEGAM_SCMADMIN_USERNAME']
60
+ password = params[:password] || ENV['MEGAM_SCMADMIN_PASSWORD']
61
+ raise ArgumentError, "You must specify [:username, :password]" if username.nil? || password.nil?
62
+ text.msg "#{text.color("Got username[#{username}] [*******]", :red, :bold)}"
63
+
64
+ begin
65
+ httpcon = connection
66
+ httpcon.use_ssl = false
67
+ httpcon.start do |http|
68
+ request = Net::HTTP::Get.new(@options[:path])
69
+ request.basic_auth username, password
70
+ @response = http.request(request)
71
+ end
72
+ end
73
+ @response
74
+ end
75
+ private
76
+
77
+ #Make a lazy connection.
78
+ def connection
79
+ @options[:path] =API_REST + @options[:path]
80
+ @options[:headers] = HEADERS.merge({
81
+ 'X-Megam-Date' => Time.now.strftime("%Y-%m-%d %H:%M")
82
+ }).merge(@options[:headers])
83
+
84
+ text.info("HTTP Request Data:")
85
+ text.msg("> HTTP #{@options[:scheme]}://#{@options[:host]}")
86
+ @options.each do |key, value|
87
+ text.msg("> #{key}: #{value}")
88
+ end
89
+ text.info("End HTTP Request Data.")
90
+ http = Net::HTTP.new(@options[:host], @options[:port])
91
+ http
92
+ end
93
+ end
94
+
95
+ end
@@ -0,0 +1,29 @@
1
+ module Megam
2
+ class Scmmanager
3
+ # GET /accounts
4
+ #Yet to be tested
5
+ def get_accounts(email)
6
+
7
+ @options = {:path => "/users.json",
8
+ :body => ''}.merge(@options)
9
+
10
+ request(
11
+ :expects => 200,
12
+ :method => :get,
13
+ :body => @options[:body]
14
+ )
15
+ end
16
+
17
+ # The body content needs to be a json.
18
+ def post_accounts(json_hash)
19
+ @options = {:path => '/users.json',
20
+ :body => json_hash[:json]}.merge(@options)
21
+
22
+ request(
23
+ :expects => 201,
24
+ :method => :post,
25
+ :body => @options[:body]
26
+ )
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,74 @@
1
+ module Megam
2
+ class Dumpout
3
+
4
+ attr_reader :stdout
5
+ attr_reader :stderr
6
+ attr_reader :stdin
7
+
8
+ def initialize(stdout, stderr, stdin)
9
+ @stdout, @stderr, @stdin = stdout, stderr, stdin
10
+ end
11
+
12
+ def highline
13
+ @highline ||= begin
14
+ require 'highline'
15
+ HighLine.new
16
+ end
17
+ end
18
+
19
+
20
+ def msg(message)
21
+ stdout.puts message
22
+ end
23
+
24
+ # Prints a message to stdout. Aliased as +info+ for compatibility with
25
+ # the logger API.
26
+
27
+ def info(message)
28
+ stdout.puts("#{color('INFO:', :green, :bold)} #{message}")
29
+ end
30
+
31
+ # Prints a msg to stderr. Used for warn, error, and fatal.
32
+ def err(message)
33
+ stderr.puts message
34
+ end
35
+
36
+ # Print a warning message
37
+ def warn(message)
38
+ err("#{color('WARNING:', :yellow, :bold)} #{message}")
39
+ end
40
+
41
+ # Print an error message
42
+ def error(message)
43
+ err("#{color('ERROR:', :red, :bold)} #{message}")
44
+ end
45
+
46
+ # Print a message describing a fatal error.
47
+ def fatal(message)
48
+ err("#{color('FATAL:', :red, :bold)} #{message}")
49
+ end
50
+
51
+ def color(string, *colors)
52
+ if color?
53
+ highline.color(string, *colors)
54
+ else
55
+ string
56
+ end
57
+ end
58
+
59
+ # Should colored output be used ?. When output is not to a
60
+ # terminal, colored output is never used
61
+ def color?
62
+ stdout.tty?
63
+ end
64
+
65
+ def list(*args)
66
+ highline.list(*args)
67
+ end
68
+
69
+ def pretty_print(data)
70
+ stdout.puts data
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,27 @@
1
+ module Megam
2
+ class Scmmanager
3
+ module Errors
4
+ class Error < StandardError; end
5
+
6
+ class ErrorWithResponse < Error
7
+ attr_reader :response
8
+
9
+ def initialize(message, response)
10
+ super message
11
+ @response = response
12
+ end
13
+
14
+
15
+ end
16
+
17
+ class Unauthorized < ErrorWithResponse; end
18
+ class Forbidden < ErrorWithResponse; end
19
+ class NotFound < ErrorWithResponse; end
20
+ class Timeout < ErrorWithResponse; end
21
+ class Locked < ErrorWithResponse; end
22
+ class Socket < ErrorWithResponse; end
23
+ class RequestFailed < ErrorWithResponse; end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ module Megam
2
+ class Scmmanager
3
+ # GET /accounts
4
+ #Yet to be tested
5
+ def get_repos(username=nil, password=nil)
6
+
7
+ @options = {:path => "/repositories",
8
+ :body => ''}.merge(@options)
9
+
10
+ request(
11
+ :expects => 200,
12
+ :method => :get,
13
+ :username => username,
14
+ :password => password,
15
+ :body => @options[:body]
16
+ )
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Megam
2
+ class Scmmanager
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require(File.join(File.dirname(__FILE__), "megam", "scmmanager"))
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "megam/scmmanager/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "megam_scmmanager"
7
+ s.version = Megam::Scmmanager::VERSION
8
+ s.authors = ["Raj Thilak,Kishorekumar Neelamegam, Thomas Alrin"]
9
+ s.email = ["rajthilak@megam.co.in","nkishore@megam.co.in","alrin@megam.co.in"]
10
+ s.homepage = "http://github.com/indykish/megam_scmmanager.rb"
11
+ s.license = "Apache V2"
12
+ sextra_rdoc_files = ["README.md", "LICENSE" ]
13
+ s.summary = %q{Ruby Client for the Scm-manager (scm-manager.org)}
14
+ s.description = %q{Ruby Client for the Scm-manager (scm-manager.org). Performs REST based HTTP call to scm-manager.org server}
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,fea,tures}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+ s.add_runtime_dependency 'highline', '~> 1.6'
20
+ s.add_runtime_dependency 'nokogiri', '~> 1.6'
21
+ s.add_development_dependency 'minitest', '~> 5.2'
22
+ s.add_development_dependency 'rake', '~> 10.1'
23
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestScm < MiniTest::Unit::TestCase
4
+
5
+ #def test_post_json
6
+ # response =megams.post_accounts(sandbox_json)
7
+ #assert_equal(200, response.status)
8
+ #end
9
+
10
+ def test_get_json
11
+ response =megams.get_accounts("rajthilak@megam.co.in")
12
+ assert_equal(200, response.status)
13
+ end
14
+
15
+ end
16
+
17
+
@@ -0,0 +1,29 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../lib/megam/scmmanager")
2
+
3
+ require 'rubygems'
4
+ gem 'minitest' # ensure we are using the gem version
5
+ require 'minitest/autorun'
6
+ require 'time'
7
+
8
+ SANDBOX_HOST_OPTIONS = {
9
+ :host => 'scm-manager.megam.co',
10
+ :port => 8080
11
+ }
12
+
13
+
14
+ def megam(options)
15
+ options = SANDBOX_HOST_OPTIONS.merge(options)
16
+ mg=Megam::Scmmanager.new(options)
17
+ end
18
+
19
+ def megams(options={})
20
+ s_options = SANDBOX_HOST_OPTIONS.merge(options)
21
+ #options = s_options.merge(options)
22
+ mg=Megam::Scmmanager.new(s_options)
23
+ end
24
+
25
+ def sandbox_json
26
+ {:json =>
27
+ '{"name":"raj", "displayName":"test", "mail":"rajthilak@megam.co.in", "password":"welcome"}'
28
+ }
29
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+ require 'nokogiri'
3
+
4
+ class TestScm < MiniTest::Unit::TestCase
5
+ def test_getrepos
6
+ response =megams.get_repos()
7
+ assert_raises(ArgumentError)
8
+ end
9
+
10
+ def test_getrepos_error
11
+ response =megams.get_repos("abcd", "abcd")
12
+ assert_raises(ArgumentError)
13
+ end
14
+
15
+ end
16
+
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: megam_scmmanager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Raj Thilak,Kishorekumar Neelamegam, Thomas Alrin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.1'
69
+ description: Ruby Client for the Scm-manager (scm-manager.org). Performs REST based
70
+ HTTP call to scm-manager.org server
71
+ email:
72
+ - rajthilak@megam.co.in
73
+ - nkishore@megam.co.in
74
+ - alrin@megam.co.in
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".project"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - lib/megam/core/scmm/scmmaccount.rb
87
+ - lib/megam/core/scmm/scmmrepo.rb
88
+ - lib/megam/scmmanager.rb
89
+ - lib/megam/scmmanager/accounts.rb
90
+ - lib/megam/scmmanager/dumpout.rb
91
+ - lib/megam/scmmanager/errors.rb
92
+ - lib/megam/scmmanager/repos.rb
93
+ - lib/megam/scmmanager/version.rb
94
+ - lib/megam_scmmanager.rb
95
+ - megam_scmmanager.gemspec
96
+ - test/test_account.rb
97
+ - test/test_helper.rb
98
+ - test/test_repo.rb
99
+ homepage: http://github.com/indykish/megam_scmmanager.rb
100
+ licenses:
101
+ - Apache V2
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.1.11
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Ruby Client for the Scm-manager (scm-manager.org)
123
+ test_files: []