megam_gogs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e37ef1937006bbf48a238650a66dbe79e54a0fb
4
+ data.tar.gz: 25c5ff746fc72387568a3a4770d62188f0a845af
5
+ SHA512:
6
+ metadata.gz: 7b766b05abce6555a3b30e1e9c270dcf3fa40edcc68f3276614f24e42938d3cb4b857a69987bdf9d8b79921e1286a4ad24ef0e510922fb8a2164cdc6ec88b47c
7
+ data.tar.gz: 0880166220a67ef51004e8dd83392555f2413e65a7a0a30f1cbd9e25c02d9bfd20a424c6cd61d684a5441b10eeabc398236b2cd53b28bddaa822aadfb1d1dfed
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
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,6 @@
1
+ Go Git Service Ruby Client
2
+ ==========================
3
+
4
+ A Go Git Service ruby client
5
+
6
+
@@ -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,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "megam/gogs/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "megam_gogs"
7
+ s.version = Megam::Gogs::VERSION
8
+ s.authors = ["Raj Thilak,Kishorekumar Neelamegam, Thomas Alrin, Yeshwanth Kumar"]
9
+ s.email = ["rajthilak@megam.co.in","nkishore@megam.co.in","alrin@megam.co.in, getyesh@megam.co.in"]
10
+ s.homepage = "http://github.com/megamsys/megam_gogs.rb"
11
+ s.license = "Apache V2"
12
+ sextra_rdoc_files = ["README.md", "LICENSE" ]
13
+ s.summary = %q{Ruby Client for the Gogs (gogs.io)}
14
+ s.description = %q{Ruby Client for the Gogs (gogs.io). Performs REST based HTTP call to gogs.io 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 @@
1
+ require(File.join(File.dirname(__FILE__), "main", "gogs"))
@@ -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 GogsAccount
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 GogsRepo
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::Gogs.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,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 GogsTokens
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::Gogs.new
39
+ res = megams.get_tokens(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,137 @@
1
+ require "time"
2
+ require "uri"
3
+ require "zlib"
4
+ require 'openssl'
5
+ require 'net/http'
6
+ require 'excon'
7
+ require 'base64'
8
+
9
+ __LIB_DIR__ = File.expand_path(File.join(File.dirname(__FILE__), ".."))
10
+ unless $LOAD_PATH.include?(__LIB_DIR__)
11
+ $LOAD_PATH.unshift(__LIB_DIR__)
12
+ end
13
+
14
+ require "megam/gogs/version"
15
+ require "megam/gogs/accounts"
16
+ require "megam/gogs/dumpout"
17
+ require "megam/gogs/errors"
18
+ require "megam/gogs/repos"
19
+ require "megam/gogs/tokens"
20
+ require "megam/core/gogs_client/gogs_repo"
21
+ require "megam/core/gogs_client/gogs_account"
22
+
23
+
24
+ module Megam
25
+ class Gogs
26
+
27
+ AUTH_PREFIX = 'Authorization'
28
+
29
+ HEADERS = {
30
+ 'Accept' => 'application/json',
31
+ 'Accept-Encoding' => 'gzip',
32
+ 'User-Agent' => "megam-gogs/#{Megam::Gogs::VERSION}",
33
+ 'X-Ruby-Version' => RUBY_VERSION,
34
+ 'X-Ruby-Platform' => RUBY_PLATFORM
35
+
36
+ }
37
+
38
+ OPTIONS = {
39
+ :headers => {},
40
+ :host => 'localhost',
41
+ :port => '3000',
42
+ :nonblock => false,
43
+ :scheme => 'http'
44
+ }
45
+
46
+ API_REST = "/api/v1"
47
+
48
+
49
+ def text
50
+ @text ||= Megam::Dumpout.new(STDOUT, STDERR, STDIN)
51
+ end
52
+
53
+ def last_response
54
+ @last_response
55
+ end
56
+
57
+ # It is assumed that every API call will NOT use an API_KEY/email.
58
+ def initialize(options={})
59
+ @options = OPTIONS.merge(options)
60
+ end
61
+
62
+ def request(params,&block)
63
+ #just_color_debug("#{@options[:path]}")
64
+ start = Time.now
65
+
66
+ dummy_params = {
67
+ :expects => params[:expects],
68
+ :method => params[:method],
69
+ :body => params[:body]
70
+ }
71
+
72
+
73
+ text.msg "#{text.color("START", :cyan, :bold)}"
74
+ params.each do |pkey, pvalue|
75
+ text.msg("> #{pkey}: #{pvalue}")
76
+ end
77
+
78
+ @uname = params[:username]
79
+ @pass = params[:password]
80
+ @cred = "#{@uname}:#{@pass}"
81
+ @tokens = params[:token]
82
+ @final_cred64 = Base64.encode64(@cred)
83
+ @final_hash = { :creds => "Basic #{@final_cred64}" }
84
+ @final_token = {:token => "token #{@tokens}"}
85
+ response = connection.request(dummy_params, &block)
86
+ puts response.inspect
87
+ text.msg("END(#{(Time.now - start).to_s}s)")
88
+ # reset (non-persistent) connection
89
+ @connection.reset
90
+ response
91
+
92
+ end
93
+
94
+
95
+ #Make a lazy connection.
96
+ def connection
97
+ @options[:path] =API_REST + @options[:path]
98
+ #headers_hash = encode_header(@options)
99
+
100
+ @options[:headers] = HEADERS.merge({ AUTH_PREFIX => @final_hash[:creds],
101
+ AUTH_PREFIX => @final_token[:token]}).merge(@options[:headers])
102
+
103
+ text.msg("HTTP Request Data:")
104
+ text.msg("> HTTP #{@options[:scheme]}://#{@options[:host]}")
105
+ @options.each do |key, value|
106
+ text.msg("> #{key}: #{value}")
107
+ end
108
+ text.msg("End HTTP Request Data.")
109
+ if @options[:scheme] == "https"
110
+ @connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}",@options)
111
+ else
112
+ Excon.defaults[:ssl_verify_peer] = false
113
+ @connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}:3000",@options)
114
+ end
115
+ @connection
116
+ end
117
+
118
+ =begin
119
+ def encode_header(cmd_parms)
120
+
121
+ #puts cmd_parms[:username]
122
+ #puts cmd_parms[:password]
123
+ @cred = "#{cmd_parms[:username]}:#{cmd_parms[:password]}"
124
+ puts @cred
125
+ puts "printing unamd and pass"
126
+ basic = 'Basic'
127
+ @final_cred64 = Base64.encode64(@cred)
128
+ puts @final_cred64
129
+ { :creds => "#{basic} #{@final_cred64}" }
130
+ end
131
+ =end
132
+
133
+
134
+
135
+
136
+ end
137
+ end
@@ -0,0 +1,29 @@
1
+ module Megam
2
+ class Gogs
3
+ # GET /accounts
4
+ #Yet to be tested
5
+ def get_accounts(uname)
6
+
7
+ @options = {:path => "/users/:uname",
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 Gogs
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,23 @@
1
+ module Megam
2
+ class Gogs
3
+
4
+ #Yet to be tested
5
+
6
+ def get_repos(token=nil)
7
+
8
+
9
+
10
+ @options = {:path => "/user/repos",
11
+ :body => ''}.merge(@options)
12
+
13
+ request(
14
+ :expects => 200,
15
+ :method => :get,
16
+ :token => token,
17
+ :body => @options[:body]
18
+
19
+ )
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ module Megam
2
+ class Gogs
3
+
4
+ def get_tokens(username=nil, password=nil)
5
+
6
+
7
+ @options = {:path => "/users/#{username}/tokens",
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
+
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ module Megam
2
+ class Gogs
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/test.rb ADDED
@@ -0,0 +1,23 @@
1
+
2
+ #$LOAD_PATH.unshift('/home/morpheyesh/code/workspace/megam/gogs.rb/lib')
3
+ #require('gogs.rb')
4
+ require 'rubygems'
5
+ require 'megam_gogs'
6
+
7
+ class Test
8
+
9
+ def self.test(uname, pass)
10
+ begin
11
+ @test = Megam::GogsRepo.list(uname, pass)
12
+ rescue ArgumentError => ae
13
+ hash = {"msg" => ae.message, "msg_type" => "error"}
14
+ re = Megam::Error.from_hash(hash)
15
+ @res = {"data" => {:body => re}}
16
+ return @res["data"][:body]
17
+ end
18
+ puts @test
19
+ @test
20
+ end
21
+ end
22
+ test(morpheyesh, 1234567)
23
+
@@ -0,0 +1,29 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../lib/megam/gogs")
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 => 'localhost',
10
+ :port => 3000
11
+ }
12
+
13
+
14
+ def megam(options)
15
+ options = SANDBOX_HOST_OPTIONS.merge(options)
16
+ mg=Megam::Gogs.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::Gogs.new(s_options)
23
+ end
24
+
25
+ def sandbox_json
26
+ {:json =>
27
+ '{"name":"Simpson", "displayName":"test", "mail":"homersimpson@springfield.com", "password":"bart"}'
28
+ }
29
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+ require 'nokogiri'
3
+
4
+ class TestGogs < MiniTest::Unit::TestCase
5
+ def test_getrepos
6
+ token = 'f39f10eda64a14fe23a3ff2ad2afdb480162d379'
7
+ response =megams.get_repos(token)
8
+ assert_raises(ArgumentError)
9
+ end
10
+ =begin
11
+ def test_getrepos_error
12
+
13
+ response =megams.get_repos("abcd", "abcd")
14
+ assert_raises(ArgumentError)
15
+ end
16
+ =end
17
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+ require 'nokogiri'
3
+
4
+ class TestGogs < MiniTest::Unit::TestCase
5
+ def test_gettokens
6
+ name = "morpheyesh"
7
+ pass = "123456"
8
+ response =megams.get_tokens(name, pass)
9
+ assert_raises(ArgumentError)
10
+
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: megam_gogs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Raj Thilak,Kishorekumar Neelamegam, Thomas Alrin, Yeshwanth Kumar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-09 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 Gogs (gogs.io). Performs REST based HTTP call to
70
+ gogs.io server
71
+ email:
72
+ - rajthilak@megam.co.in
73
+ - nkishore@megam.co.in
74
+ - alrin@megam.co.in, getyesh@megam.co.in
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - gogs_api.gemspec
85
+ - lib/gogs_api.rb
86
+ - lib/megam/core/gogs_client/gogs_account.rb
87
+ - lib/megam/core/gogs_client/gogs_repo.rb
88
+ - lib/megam/core/gogs_client/gogs_tokens.rb
89
+ - lib/megam/gogs.rb
90
+ - lib/megam/gogs/accounts.rb
91
+ - lib/megam/gogs/dumpout.rb
92
+ - lib/megam/gogs/errors.rb
93
+ - lib/megam/gogs/repos.rb
94
+ - lib/megam/gogs/tokens.rb
95
+ - lib/megam/gogs/version.rb
96
+ - test.rb
97
+ - test/test_helper.rb
98
+ - test/test_repo.rb
99
+ - test/test_tokens.rb
100
+ homepage: http://github.com/megamsys/megam_gogs.rb
101
+ licenses:
102
+ - Apache V2
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.5
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Ruby Client for the Gogs (gogs.io)
124
+ test_files:
125
+ - test/test_helper.rb
126
+ - test/test_repo.rb
127
+ - test/test_tokens.rb