nclient 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'rest-client', '~> 1.6.7' #add runtime dependencies
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.6.4"
14
+ gem "rcov", ">= 0"
15
+ end
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ mime-types (1.17.2)
10
+ rake (0.9.2.2)
11
+ rcov (0.9.11)
12
+ rest-client (1.6.7)
13
+ mime-types (>= 1.16)
14
+ shoulda (2.11.3)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.0.0)
21
+ jeweler (~> 1.6.4)
22
+ rcov
23
+ rest-client (~> 1.6.7)
24
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 caory
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ = nclient
2
+
3
+ 更加便利支持ns_service_pack在客户端的应用
4
+
5
+ #==功能列表:
6
+ * 提供service配置管理
7
+ * 统一错误处理
8
+
9
+ #==使用指南
10
+
11
+
12
+ #==History:
13
+
14
+ #==0.0.5
15
+ * 初期代码
16
+ * 添加rest-client运行时依赖,可以不在宿主项目中添加gem 'rest-client'即可引用项目
17
+
18
+ #==0.0.1
19
+ * 抽离基本代码
20
+
21
+ #==20111120
22
+ 希望将客户端共用代码抽离成gem包形式
23
+
24
+ == Contributing to nclient
25
+
26
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
27
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
28
+ * Fork the project
29
+ * Start a feature/bugfix branch
30
+ * Commit and push until you are happy with your contribution
31
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
32
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
33
+
34
+ == Copyright
35
+
36
+ Copyright (c) 2011 caory. See LICENSE.txt for
37
+ further details.
38
+
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "nclient"
18
+ gem.homepage = "http://github.com/cao7113/nclient"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{client pack for little project}
21
+ gem.description = %Q{client pack for ns_service_pack}
22
+ gem.email = "cao7113@hotmail.com"
23
+ gem.authors = ["caory"]
24
+ gem.executables = ['nclient']
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "nclient #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.6
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/ruby
2
+
3
+ puts "hello..."
@@ -0,0 +1,13 @@
1
+ #coding: utf-8
2
+ NCLIENT_GEM_ROOT = File.expand_path('../..', __FILE__)
3
+
4
+ require 'nclient/version'
5
+ require 'nclient/util'
6
+ require 'nclient/result'
7
+ require 'nclient/result_error'
8
+ require 'nclient/client'
9
+ require 'nclient/service_config'
10
+
11
+ module NClient
12
+ end
13
+
@@ -0,0 +1,40 @@
1
+ #coding: utf-8
2
+ require 'rest_client'
3
+
4
+ module Ns
5
+ class Client
6
+ #delegate :new, :get, :post, :to=>RestClient::Resource TODO ??
7
+ def self.get(url = '', params = {})
8
+ #params TODO
9
+ request('get', url, params)
10
+ end
11
+
12
+ def self.post(url = '', params = {})
13
+ request('post', url, params)
14
+ end
15
+
16
+ def self.put(url = '', params = {})
17
+ request('put', url, params)
18
+ end
19
+
20
+ def self.delete()
21
+ end
22
+
23
+ def self.request(action = 'get', url = '', data_params = {})
24
+ #TODO 网路异常处理
25
+ #use RestClient now
26
+ json_response = RestClient.send(action, url, :data=>data_params)
27
+ result = unpack(json_response)
28
+ if result.ok?
29
+ return result.data.symbolize_keys if result.data.is_a?(Hash)
30
+ result.data
31
+ else
32
+ raise ResultError.new(result)
33
+ end
34
+ end
35
+
36
+ def self.unpack(json_response_str = nil)
37
+ Result.new(JSON.parse(json_response_str))
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ #coding: utf-8
2
+
3
+ module Ns
4
+ #TODO 封装在gem包中
5
+ class Result
6
+ STATUSES = [:ok, :imperfect, :illegal, :error]
7
+ attr_accessor :status, :msg, :data, :errors
8
+ def initialize(params = {})
9
+ _params = params.symbolize_keys
10
+ @status = _params[:status]
11
+ @msg = _params[:msg]
12
+ @data = _params[:data]
13
+ @errors = _params[:errors]
14
+ end
15
+
16
+ def ok?
17
+ status == 'ok'
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,17 @@
1
+ #coding: utf-8
2
+
3
+ module Ns
4
+ class ResultError < RuntimeError
5
+ attr_reader :result
6
+ def initialize(result = nil)
7
+ raise "Invalid result argument!" unless result.is_a?(Result)
8
+ super(result.msg)
9
+ @result = result
10
+ end
11
+
12
+ def to_s
13
+ "RusultError: #{@result.status} #{@result.msg}, detail: #{@result.errors.inspect}"
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,29 @@
1
+ #coding: utf-8
2
+ module Ns
3
+ class ServiceConfig
4
+ SERVICE_CONFIG_FILE = 'config/services.yml'
5
+ cattr_accessor :services
6
+ @@services = {}
7
+
8
+ def self.load_services!(config_file = SERVICE_CONFIG_FILE)
9
+ service_configs = YAML.load(File.read(SERVICE_CONFIG_FILE))
10
+ @@services.merge!(service_configs[Rails.env])
11
+ #load common parts if exists
12
+ if (common_parts = service_configs['common']).is_a?(Hash)
13
+ common_parts.each do |k, v|
14
+ @@services[k] = if v.is_a?(Array)
15
+ if v.size == 2
16
+ v[0] = @@services[v[0].to_sym]
17
+ Ns::Util.concat_url(v[0], v[1])
18
+ else
19
+ raise "Invalid path!"
20
+ end #/if
21
+ else
22
+ v
23
+ end #/if
24
+ end #/do
25
+ end #/if
26
+ @@services
27
+ end #/def
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ #coding: utf-8
2
+ module Ns
3
+ module Util
4
+ extend self
5
+ def concat_url(prefix_url='', url='')
6
+ prefix_url = prefix_url.to_s
7
+ sep = (prefix_url[-1, 1] == '/' || url[0, 1] == '/') ? '' : '/'
8
+ "#{prefix_url}#{sep}#{url}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ #coding: utf-8
2
+ module NClient
3
+ VERSION = '0.0.5'
4
+ end
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "nclient"
8
+ s.version = "0.0.6"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["caory"]
12
+ s.date = "2011-11-24"
13
+ s.description = "client pack for ns_service_pack"
14
+ s.email = "cao7113@hotmail.com"
15
+ s.executables = ["nclient"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/nclient",
29
+ "lib/nclient.rb",
30
+ "lib/nclient/client.rb",
31
+ "lib/nclient/result.rb",
32
+ "lib/nclient/result_error.rb",
33
+ "lib/nclient/service_config.rb",
34
+ "lib/nclient/util.rb",
35
+ "lib/nclient/version.rb",
36
+ "nclient.gemspec",
37
+ "test/helper.rb",
38
+ "test/test_nclient.rb"
39
+ ]
40
+ s.homepage = "http://github.com/cao7113/nclient"
41
+ s.licenses = ["MIT"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = "1.8.10"
44
+ s.summary = "client pack for little project"
45
+
46
+ if s.respond_to? :specification_version then
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.7"])
51
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<rest-client>, ["~> 1.6.7"])
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<rest-client>, ["~> 1.6.7"])
64
+ s.add_dependency(%q<shoulda>, [">= 0"])
65
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
67
+ s.add_dependency(%q<rcov>, [">= 0"])
68
+ end
69
+ end
70
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'nclient'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestNclient < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nclient
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - caory
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-24 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: &86812150 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *86812150
25
+ - !ruby/object:Gem::Dependency
26
+ name: shoulda
27
+ requirement: &86811910 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *86811910
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &86811670 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *86811670
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &86811430 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *86811430
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &86811190 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *86811190
69
+ description: client pack for ns_service_pack
70
+ email: cao7113@hotmail.com
71
+ executables:
72
+ - nclient
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - LICENSE.txt
76
+ - README.rdoc
77
+ files:
78
+ - .document
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.rdoc
83
+ - Rakefile
84
+ - VERSION
85
+ - bin/nclient
86
+ - lib/nclient.rb
87
+ - lib/nclient/client.rb
88
+ - lib/nclient/result.rb
89
+ - lib/nclient/result_error.rb
90
+ - lib/nclient/service_config.rb
91
+ - lib/nclient/util.rb
92
+ - lib/nclient/version.rb
93
+ - nclient.gemspec
94
+ - test/helper.rb
95
+ - test/test_nclient.rb
96
+ homepage: http://github.com/cao7113/nclient
97
+ licenses:
98
+ - MIT
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ segments:
110
+ - 0
111
+ hash: -13951149
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 1.8.10
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: client pack for little project
124
+ test_files: []