lean_cloud 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3bdcc7d98e55c298d4036e11dbf7f9cd209e969c
4
+ data.tar.gz: d696b5333a506609c1de167fbcc8b9f1710fb163
5
+ SHA512:
6
+ metadata.gz: e5db0df3d790166bff799638f9e717bf23881734b963ddca826992bc5f09c03e4291984836905ea42eb7575a716c95b194f8c9ba28e2347899a5627c20c826af
7
+ data.tar.gz: 991f034528d3a19001f013c81803d26d69e1449fb835cf43df58ed8b542bd3edfc8e425633ea70203ba29d30c548197ba768955aee7c33d57b606eb45a1c8e6c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
8
+ test/dummy/.sass-cache
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in lean_cloud.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use debugger
14
+ # gem 'debugger'
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
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.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # LeanCloud
2
+
3
+ This project rocks and uses MIT-LICENSE.
4
+
5
+ # 配置
6
+
7
+ ```
8
+ LeanCloud.configure do
9
+ config.app_id = "11f6ad8ec52a2984abaafd7c3b516503785c2072"
10
+ config.app_key = "11f6ad8ec52a2984abaafd7c3b516503785c2072"
11
+ config.host = "https://leancloud.cn"
12
+ config.version = "1.1"
13
+ end
14
+ ```
15
+
16
+ # 在数据管理中添加一个class(GameScore)后:
17
+
18
+ ```
19
+ LeanCloud.register "GameScore", namespace: "classes/GameScore" do
20
+ only :create, :update, :show, :destroy, :search
21
+ end
22
+ ```
23
+
24
+ ```
25
+ 然后使用如下方式进行调用接口
26
+ LeanCloud::GameScore.create({score: 'xxx'})
27
+ LeanCloud::GameScore.show("11f6ad8ec52a2984abaafd7c3b516503785c2072")
28
+ LeanCloud::GameScore.update("11f6ad8ec52a2984abaafd7c3b516503785c2072", {score: 'e'})
29
+ LeanCloud::GameScore.destroy("11f6ad8ec52a2984abaafd7c3b516503785c2072")
30
+ LeanCloud::GameScore.search(where: {post: {_type: 'xxx'}})
31
+ ```
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'LeanCloud'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,24 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "lean_cloud/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "lean_cloud"
9
+ s.version = LeanCloud::VERSION
10
+ s.authors = ["plusrez"]
11
+ s.email = ["plusor@icloud.com"]
12
+ s.homepage = "https://github.com/plusrez/lean_cloud"
13
+ s.summary = "LeanCloud SDK."
14
+ s.description = "LeanCloud SDK."
15
+ s.license = "MIT"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = Dir["test/**/*"]
19
+
20
+ s.add_dependency "faraday"
21
+ s.add_dependency "activesupport"
22
+ s.add_development_dependency 'rake', '~> 0.9.2'
23
+ s.add_development_dependency 'rspec', '~> 2.5'
24
+ end
@@ -0,0 +1,43 @@
1
+ require 'lean_cloud'
2
+ require 'lean_cloud/helper'
3
+ require 'lean_cloud/client'
4
+ require 'active_support/core_ext/module/attribute_accessors'
5
+ require 'active_support/json/decoding'
6
+ require 'active_support/json/encoding'
7
+ module LeanCloud
8
+ class Base
9
+ class NotImplement < StandardError ; end
10
+
11
+ class << self
12
+ def register(klass, options={}, &block)
13
+ klass = if !LeanCloud.const_defined?(klass)
14
+ LeanCloud.const_set(klass, Class.new(self))
15
+ else
16
+ LeanCloud.const_get(klass)
17
+ end
18
+
19
+ klass.class_eval do
20
+ include Helper
21
+
22
+ cattr_accessor :routes, :namespace
23
+
24
+ self.routes ||= []
25
+ self.namespace = options[:namespace]
26
+
27
+
28
+
29
+ class_exec(&block)
30
+ end
31
+ end
32
+
33
+ def client
34
+ Client.new(LeanCloud.config).instance
35
+ end
36
+
37
+ def dispatch(route, *args, &block)
38
+ options = args.extract_options!
39
+ client.send(route.request, route.url(*args), options.to_json, &block)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,31 @@
1
+ require 'active_support/hash_with_indifferent_access'
2
+ require 'active_support/core_ext/module/delegation'
3
+ module LeanCloud
4
+ class Client
5
+
6
+ attr_accessor :options
7
+
8
+ delegate :app_id, :app_key, :version, :http_adapter, :host, to: :options
9
+ delegate :get, :put, :post, :delete, to: :instance
10
+
11
+ def initialize(options)
12
+ @options = options
13
+ end
14
+
15
+ def adapter
16
+ http_adapter
17
+ end
18
+
19
+ def instance
20
+ adapter.new(url, headers: headers)
21
+ end
22
+
23
+ def headers
24
+ {"X-AVOSCloud-Application-Id" => app_id, "X-AVOSCloud-Application-Key" => app_key, 'Content-Type' => 'application/json' }
25
+ end
26
+
27
+ def url
28
+ [host, version].join('/')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ require 'faraday'
2
+ module LeanCloud
3
+ class Configuration
4
+ class << self
5
+ private :new
6
+ def instance
7
+ @instance ||= new
8
+ end
9
+ end
10
+
11
+ def initialize
12
+ @@options = {
13
+ :http_adapter => Faraday,
14
+ :app_id => nil,
15
+ :app_key => nil
16
+ }
17
+ end
18
+
19
+ def respond_to?(name, include_private = false)
20
+ super || @@options.key?(name.to_sym)
21
+ end
22
+
23
+ private
24
+
25
+ def method_missing(name, *args, &blk)
26
+ if name.to_s =~ /=$/
27
+ @@options[$`.to_sym] = args.first
28
+ elsif @@options.key?(name)
29
+ @@options[name]
30
+ else
31
+ super
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,48 @@
1
+ require 'active_support/concern'
2
+ require 'lean_cloud/route'
3
+ module LeanCloud
4
+ module Helper
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ DEFAULT_ACTIONS = {
9
+ :search => {via: :get, root: true },
10
+ :show => {via: :get, root: true, on: :member },
11
+ :create => {via: :post, root: true },
12
+ :update => {via: :put, root: true, on: :member },
13
+ :destroy=> {via: :delete, root: true, on: :member }
14
+ }
15
+ def only(*args)
16
+ args.each do |action|
17
+ add_route(action, DEFAULT_ACTIONS[action].dup)
18
+ end
19
+ end
20
+
21
+ def route(name, options={})
22
+ add_route(name, options)
23
+ end
24
+
25
+ def match(name, options={})
26
+ raise "`as' can't be nil!" if !options[:as]
27
+ add_route(options.delete(:as), options, name)
28
+ end
29
+
30
+ def add_route(name, options={},match=nil)
31
+ options[:namespace] ||= namespace
32
+ routes << Route.new(name, options, match)
33
+ end
34
+
35
+ def respond_to?(method_id)
36
+ routes.any? {|route| route.name.to_s == method_id.to_s}
37
+ end
38
+
39
+ def method_missing(method_id, *args, &block)
40
+ if route=routes.find {|route| route.name.to_s == method_id.to_s}
41
+ dispatch(route, *args, &block)
42
+ else
43
+ super
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,6 @@
1
+ # 对象接口
2
+ # LeanCloud::Base.register "GameScore", namespace: "classes/GameScore" do
3
+ # only :create, :update, :show, :destroy, :search # create update destroy show search
4
+ # # # /1.1/cloudQuery GET 使用 CQL 查询对象
5
+ # route :cloudQuery
6
+ # end
@@ -0,0 +1,6 @@
1
+ # 用户反馈组件接口
2
+ LeanCloud::Base.register "Feedback", namespace: "feedback" do
3
+ # /1.1/feedback
4
+ # 提交新的用户反馈
5
+ only :create
6
+ end
@@ -0,0 +1,6 @@
1
+ # Cloud 函数接口
2
+ LeanCloud::Base.register "Function", namespace: "functions" do
3
+ # /1.1/functions
4
+ # 调用 Cloud Code 函数
5
+ only :create
6
+ end
@@ -0,0 +1,4 @@
1
+ # 安装数据
2
+ LeanCloud::Base.register "Installation", namespace: "installations" do
3
+ only :create, :update, :show, :destroy, :search
4
+ end
@@ -0,0 +1,5 @@
1
+ LeanCloud::Base.register "Message", namespace: "messages" do
2
+ # /1.1/rtm/messages/logs/
3
+ # 获得应用聊天记录
4
+ route :logs
5
+ end
@@ -0,0 +1,5 @@
1
+ # 推送通知
2
+ LeanCloud::Base.register "Push", namespace: "push" do
3
+ # /1.1/push POST 推送通知
4
+ only :create
5
+ end
@@ -0,0 +1,4 @@
1
+ # 角色接口
2
+ LeanCloud::Base.register "Role", namespace: "roles" do
3
+ only :create, :update, :show, :destroy, :search
4
+ end
@@ -0,0 +1,9 @@
1
+ # 短信验证API接口
2
+ LeanCloud::Base.register "Sms" do
3
+ # /1.1/requestSmsCode
4
+ # 请求发送短信验证码
5
+ route :requestSmsCode, via: :post
6
+ # /1.1/verifySmsCode/<code>
7
+ # 验证短信验证码
8
+ match "verifySmsCode/:code", via: :post, as: :verify_sms_code
9
+ end
@@ -0,0 +1,8 @@
1
+ LeanCloud::Base.register "Stats",namespace: "stats" do
2
+ # /1.1/stats/appinfo
3
+ # 获取应用的基本信息
4
+ route :appinfo, via: :post
5
+ # /1.1/stats/appmetrics
6
+ # 获取应用的具体统计数据
7
+ route :appmetrics, via: :post
8
+ end
@@ -0,0 +1,21 @@
1
+ LeanCloud::Base.register "User", namespace: "users" do
2
+ only :create, :update, :show, :destroy, :search
3
+ # /1.1/login GET 用户登录
4
+ route :login, via: :get, unscope: true
5
+ # /1.1/users/<objectId>/updatePassword PUT 更新密码,要求输入旧密码。
6
+ route :updatePassword, via: :put, on: :member
7
+ # /1.1/requestPasswordReset POST 请求密码重设
8
+ route :requestPasswordReset, via: :post
9
+ # /1.1/requestEmailVerify POST 请求验证用户邮箱
10
+ route :requestEmailVerify, via: :post
11
+ # /1.1/requestMobilePhoneVerify POST 请求发送用户手机号码验证短信
12
+ route :requestMobilePhoneVerify, via: :post
13
+ # /1.1/verifyMobilePhone/<code> POST 使用 "验证码" 验证用户手机号码
14
+ match "verifyMobilePhone/:code", via: :post, as: :verify_mobile_phone
15
+ # /1.1/requestLoginSmsCode POST 请求发送手机号码登录短信。
16
+ route :requestLoginSmsCode, via: :post
17
+ # /1.1/requestPasswordResetBySmsCode POST 请求发送手机短信验证码重置用户密码。
18
+ route :requestPasswordResetBySmsCode, via: :post
19
+ # /1.1/resetPasswordBySmsCode/<code> PUT 验证手机短信验证码并重置密码。
20
+ match "resetPasswordBySmsCode/:code", via: :put, as: :reset_password_by_sms_code
21
+ end
@@ -0,0 +1,11 @@
1
+ require 'lean_cloud/base'
2
+ require 'lean_cloud/modules/classes'
3
+ require 'lean_cloud/modules/feedback'
4
+ require 'lean_cloud/modules/function'
5
+ require 'lean_cloud/modules/installation'
6
+ require 'lean_cloud/modules/message'
7
+ require 'lean_cloud/modules/push'
8
+ require 'lean_cloud/modules/role'
9
+ require 'lean_cloud/modules/sms'
10
+ require 'lean_cloud/modules/stats'
11
+ require 'lean_cloud/modules/user'
@@ -0,0 +1,19 @@
1
+ module LeanCloud
2
+ class Route
3
+ attr_accessor :name, :request, :match, :options
4
+ def initialize(name, options, match=false)
5
+ options[:on] ||= :collection
6
+ @name = name
7
+ @request = options[:via] ||= :get
8
+ @match = match
9
+ @options = options
10
+ end
11
+
12
+ def url(*args)
13
+ namespace = options[:namespace] if !options[:unscope]
14
+ id = args.shift if options[:on].to_sym == :member
15
+ path = !match ? name.to_s : match.sub(/(:\w+)/, args[0]) if !options[:root]
16
+ [namespace, id, path].compact.join('/')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module LeanCloud
2
+ VERSION = "0.0.1"
3
+ end
data/lib/lean_cloud.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'lean_cloud/modules'
2
+ require 'lean_cloud/configuration'
3
+ module LeanCloud
4
+ class << self
5
+
6
+ def configure(&block)
7
+ class_exec(&block)
8
+ end
9
+
10
+ def config
11
+ @config ||= Configuration.instance
12
+ end
13
+ end
14
+
15
+ def config
16
+ self.class.config
17
+ end
18
+ end
data/test/base_test.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe LeanCloud do
4
+ describe 'test' do
5
+ it 'test' do
6
+ LeanCloud::User.search
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'lean_cloud'
5
+ require 'rspec'
6
+ require 'rspec/autorun'
7
+ RSpec.configure do |config|
8
+ #...
9
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lean_cloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - plusrez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.5'
69
+ description: LeanCloud SDK.
70
+ email:
71
+ - plusor@icloud.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - MIT-LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - lean_cloud.gemspec
82
+ - lib/lean_cloud.rb
83
+ - lib/lean_cloud/base.rb
84
+ - lib/lean_cloud/client.rb
85
+ - lib/lean_cloud/configuration.rb
86
+ - lib/lean_cloud/helper.rb
87
+ - lib/lean_cloud/modules.rb
88
+ - lib/lean_cloud/modules/classes.rb
89
+ - lib/lean_cloud/modules/feedback.rb
90
+ - lib/lean_cloud/modules/function.rb
91
+ - lib/lean_cloud/modules/installation.rb
92
+ - lib/lean_cloud/modules/message.rb
93
+ - lib/lean_cloud/modules/push.rb
94
+ - lib/lean_cloud/modules/role.rb
95
+ - lib/lean_cloud/modules/sms.rb
96
+ - lib/lean_cloud/modules/stats.rb
97
+ - lib/lean_cloud/modules/user.rb
98
+ - lib/lean_cloud/route.rb
99
+ - lib/lean_cloud/version.rb
100
+ - test/base_test.rb
101
+ - test/spec_helper.rb
102
+ homepage: https://github.com/plusrez/lean_cloud
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.2.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: LeanCloud SDK.
126
+ test_files:
127
+ - test/base_test.rb
128
+ - test/spec_helper.rb