dm-parse 0.2.3 → 0.3.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.
data/Gemfile CHANGED
@@ -18,4 +18,4 @@ end
18
18
  gem "dm-core", ">= 1.2"
19
19
  gem "dm-validations", ">= 1.2"
20
20
  gem "activesupport", ">= 3.2"
21
- gem "nestful", ">= 0.0.8"
21
+ gem "parse-ruby-client", ">= 0.0.8"
data/Gemfile.lock CHANGED
@@ -27,8 +27,10 @@ GEM
27
27
  rdoc
28
28
  json (1.7.3)
29
29
  multi_json (1.3.6)
30
- nestful (0.0.8)
31
- activesupport (>= 3.0.0.beta)
30
+ parse-ruby-client (0.1.0)
31
+ patron
32
+ vcr
33
+ patron (0.4.18)
32
34
  rake (0.9.2.2)
33
35
  rdoc (3.12)
34
36
  json (~> 1.4)
@@ -44,6 +46,7 @@ GEM
44
46
  multi_json (~> 1.0)
45
47
  simplecov-html (~> 0.5.3)
46
48
  simplecov-html (0.5.3)
49
+ vcr (2.2.2)
47
50
  yard (0.8.2.1)
48
51
 
49
52
  PLATFORMS
@@ -56,7 +59,7 @@ DEPENDENCIES
56
59
  dm-core (>= 1.2)
57
60
  dm-validations (>= 1.2)
58
61
  jeweler (>= 1.8.3)
59
- nestful (>= 0.0.8)
62
+ parse-ruby-client (>= 0.0.8)
60
63
  rdoc (>= 3.12)
61
64
  rspec (>= 2.10.0)
62
65
  simplecov (>= 0.6)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.3.0
data/dm-parse.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dm-parse"
8
- s.version = "0.2.3"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Zhi-Qiang Lei"]
@@ -34,7 +34,6 @@ Gem::Specification.new do |s|
34
34
  "lib/is/parse.rb",
35
35
  "lib/parse/engine.rb",
36
36
  "lib/parse/query.rb",
37
- "lib/parse/resource.rb",
38
37
  "lib/property/parse_date.rb",
39
38
  "lib/property/parse_file.rb",
40
39
  "lib/property/parse_geo_point.rb",
@@ -48,7 +47,6 @@ Gem::Specification.new do |s|
48
47
  "spec/parse_key_spec.rb",
49
48
  "spec/parse_pointer_spec.rb",
50
49
  "spec/query_spec.rb",
51
- "spec/resource_spec.rb",
52
50
  "spec/spec_helper.rb"
53
51
  ]
54
52
  s.homepage = "https://github.com/siegfried/dm-parse"
@@ -64,7 +62,7 @@ Gem::Specification.new do |s|
64
62
  s.add_runtime_dependency(%q<dm-core>, [">= 1.2"])
65
63
  s.add_runtime_dependency(%q<dm-validations>, [">= 1.2"])
66
64
  s.add_runtime_dependency(%q<activesupport>, [">= 3.2"])
67
- s.add_runtime_dependency(%q<nestful>, [">= 0.0.8"])
65
+ s.add_runtime_dependency(%q<parse-ruby-client>, [">= 0.0.8"])
68
66
  s.add_development_dependency(%q<rspec>, [">= 2.10.0"])
69
67
  s.add_development_dependency(%q<yard>, [">= 0.7"])
70
68
  s.add_development_dependency(%q<rdoc>, [">= 3.12"])
@@ -76,7 +74,7 @@ Gem::Specification.new do |s|
76
74
  s.add_dependency(%q<dm-core>, [">= 1.2"])
77
75
  s.add_dependency(%q<dm-validations>, [">= 1.2"])
78
76
  s.add_dependency(%q<activesupport>, [">= 3.2"])
79
- s.add_dependency(%q<nestful>, [">= 0.0.8"])
77
+ s.add_dependency(%q<parse-ruby-client>, [">= 0.0.8"])
80
78
  s.add_dependency(%q<rspec>, [">= 2.10.0"])
81
79
  s.add_dependency(%q<yard>, [">= 0.7"])
82
80
  s.add_dependency(%q<rdoc>, [">= 3.12"])
@@ -89,7 +87,7 @@ Gem::Specification.new do |s|
89
87
  s.add_dependency(%q<dm-core>, [">= 1.2"])
90
88
  s.add_dependency(%q<dm-validations>, [">= 1.2"])
91
89
  s.add_dependency(%q<activesupport>, [">= 3.2"])
92
- s.add_dependency(%q<nestful>, [">= 0.0.8"])
90
+ s.add_dependency(%q<parse-ruby-client>, [">= 0.0.8"])
93
91
  s.add_dependency(%q<rspec>, [">= 2.10.0"])
94
92
  s.add_dependency(%q<yard>, [">= 0.7"])
95
93
  s.add_dependency(%q<rdoc>, [">= 3.12"])
data/lib/dm-parse.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  require "dm-core"
2
2
  require "dm-validations"
3
3
  require "active_support/all"
4
- require "nestful"
5
4
  require "collection"
5
+ require "parse-ruby-client"
6
6
  require "property/parse_key"
7
7
  require "property/parse_pointer"
8
8
  require "property/parse_date"
9
9
  require "property/parse_file"
10
10
  require "property/parse_geo_point"
11
- require "parse/resource"
12
11
  require "parse/engine"
13
12
  require "parse/query"
14
13
  require "adapters/parse_adapter"
data/lib/parse/engine.rb CHANGED
@@ -1,73 +1,76 @@
1
1
  module DataMapper
2
+
3
+ module ::Parse
4
+ module Protocol
5
+ HEADER_MASTER_KEY = "X-Parse-Master-Key"
6
+ end
7
+
8
+ class Client
9
+ def initialize(data = {})
10
+ @host = data[:host] || Protocol::HOST
11
+ @app_id = data[:app_id]
12
+ @api_key = data[:api_key]
13
+ @session = Patron::Session.new
14
+ @session.timeout = 10
15
+ @session.connect_timeout = 10
16
+
17
+ @session.base_url = "https://#{host}"
18
+ @session.headers["Content-Type"] = "application/json"
19
+ @session.headers["Accept"] = "application/json"
20
+ @session.headers["User-Agent"] = "Parse for Ruby, 0.0"
21
+ @session.headers[Protocol::HEADER_APP_ID] = @app_id
22
+
23
+ key_type = data[:master] ? Protocol::HEADER_MASTER_KEY : Protocol::HEADER_API_KEY
24
+ @session.headers[key_type] = @api_key
25
+ end
26
+ end
27
+ end
28
+
2
29
  module Parse
3
30
 
4
31
  class Engine
5
32
 
6
- HOST = "https://api.parse.com"
7
- VERSION = "1"
8
- APP_ID_HEADER = "X-Parse-Application-Id"
9
- API_KEY_HEADER = "X-Parse-REST-API-Key"
10
- MASTER_KEY_HEADER = "X-Parse-Master-Key"
11
-
12
- attr_reader :classes, :users, :login, :password_reset, :file_storage
33
+ attr_reader :client
13
34
 
14
35
  def initialize(app_id, api_key, master)
15
- @app_id = app_id
16
- @api_key = api_key
17
- @master = master
18
- @classes = build_parse_resource_for "classes"
19
- @users = build_parse_resource_for "users"
20
- @login = build_parse_resource_for "login"
21
- @password_reset = build_parse_resource_for "requestPasswordReset"
22
- @file_storage = build_parse_resource_for "files"
36
+ @client = ::Parse::Client.new app_id: app_id, api_key: api_key, master: master
23
37
  end
24
38
 
25
39
  def read(storage_name, params)
26
- parse_resources_for(storage_name).get params: params
40
+ query = params.inject({}) do |result, (k, v)|
41
+ result.merge k.to_s => CGI.escape(v.to_s)
42
+ end
43
+ client.request uri_for(storage_name), :get, nil, query
27
44
  end
28
45
 
29
46
  def delete(storage_name, id)
30
- parse_resources_for(storage_name)[id].delete
47
+ client.delete uri_for(storage_name, id)
31
48
  end
32
49
 
33
50
  def create(storage_name, attributes)
34
- parse_resources_for(storage_name).post body: attributes.to_json
51
+ client.post uri_for(storage_name), attributes.to_json
35
52
  end
36
53
 
37
54
  def update(storage_name, id, attributes)
38
- parse_resources_for(storage_name)[id].put body: attributes.to_json
55
+ client.put uri_for(storage_name, id), attributes.to_json
39
56
  end
40
57
 
41
58
  def sign_in(username, password)
42
- login.get params: {username: username, password: password}
59
+ client.request ::Parse::Protocol::USER_LOGIN_URI, :get, nil, { username: username, password: password }
43
60
  end
44
61
 
45
62
  def upload_file(filename, content, content_type)
46
- storage = file_storage[URI.escape(filename)]
47
- storage.options[:headers]["Content-Type"] = content_type
48
- storage.post body: content
63
+ client.post ::Parse::Protocol.file_uri(URI.escape(filename)), content
49
64
  end
50
65
 
51
66
  def request_password_reset(email)
52
- password_reset.post params: {email: email}
67
+ client.post ::Parse::Protocol::PASSWORD_RESET_URI, {email: email}.to_json
53
68
  end
54
69
 
55
70
  private
56
71
 
57
- def parse_resources_for(storage_name)
58
- storage_name == "_User" ? users : classes[storage_name]
59
- end
60
-
61
- def build_parse_resource_for(name)
62
- Parse::Resource.new(HOST, format: :json, headers: key_headers)[VERSION][name]
63
- end
64
-
65
- def key_headers
66
- key_type = @master ? MASTER_KEY_HEADER : API_KEY_HEADER
67
- {
68
- APP_ID_HEADER => @app_id,
69
- key_type => @api_key
70
- }
72
+ def uri_for(storage_name, id = nil)
73
+ storage_name == "_User" ? ::Parse::Protocol.user_uri(id) : ::Parse::Protocol.class_uri(storage_name, id)
71
74
  end
72
75
 
73
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-parse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -60,7 +60,7 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.2'
62
62
  - !ruby/object:Gem::Dependency
63
- name: nestful
63
+ name: parse-ruby-client
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
@@ -212,7 +212,6 @@ files:
212
212
  - lib/is/parse.rb
213
213
  - lib/parse/engine.rb
214
214
  - lib/parse/query.rb
215
- - lib/parse/resource.rb
216
215
  - lib/property/parse_date.rb
217
216
  - lib/property/parse_file.rb
218
217
  - lib/property/parse_geo_point.rb
@@ -226,7 +225,6 @@ files:
226
225
  - spec/parse_key_spec.rb
227
226
  - spec/parse_pointer_spec.rb
228
227
  - spec/query_spec.rb
229
- - spec/resource_spec.rb
230
228
  - spec/spec_helper.rb
231
229
  homepage: https://github.com/siegfried/dm-parse
232
230
  licenses:
@@ -243,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
241
  version: '0'
244
242
  segments:
245
243
  - 0
246
- hash: -4320882830707755701
244
+ hash: 1440756048767751093
247
245
  required_rubygems_version: !ruby/object:Gem::Requirement
248
246
  none: false
249
247
  requirements:
@@ -1,56 +0,0 @@
1
- module DataMapper
2
- module Parse
3
- # Read the body to get detail of Parse error
4
- class Connection < ::Nestful::Connection
5
- def handle_response(response)
6
- response.read_body if (400...500).include? response.code.to_i
7
- super
8
- end
9
- end
10
-
11
- ::Nestful::Request.class_eval do
12
- def connection
13
- conn = Connection.new(uri, format)
14
- conn.proxy = proxy if proxy
15
- conn.user = user if user
16
- conn.password = password if password
17
- conn.auth_type = auth_type if auth_type
18
- conn.timeout = timeout if timeout
19
- conn.ssl_options = ssl_options if ssl_options
20
- conn
21
- end
22
- end # This is a workaround. Mixin for Connection does not work somehow.
23
-
24
- module ParseError
25
- def to_s
26
- error = JSON.parse(response.body)["error"]
27
- super + " Response Parse Error = #{error}"
28
- end
29
- end
30
-
31
- ::Nestful::BadRequest.send :include, ParseError
32
- ::Nestful::UnauthorizedAccess.send :include, ParseError
33
- ::Nestful::ForbiddenAccess.send :include, ParseError
34
- ::Nestful::ResourceNotFound.send :include, ParseError
35
- ::Nestful::MethodNotAllowed.send :include, ParseError
36
- ::Nestful::ResourceConflict.send :include, ParseError
37
- ::Nestful::ResourceGone.send :include, ParseError
38
- ::Nestful::ResourceInvalid.send :include, ParseError
39
-
40
- class Resource < ::Nestful::Resource
41
- attr_reader :options
42
-
43
- def ==(resource)
44
- url == resource.url && options == resource.options
45
- end
46
-
47
- def delete(options = {})
48
- Nestful.delete(url, options.merge(@options))
49
- end
50
-
51
- def put(options = {})
52
- Nestful.put(url, options.merge(@options))
53
- end
54
- end
55
- end
56
- end
@@ -1,5 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DataMapper::Parse::Resource do
4
- pending "there may be tests in the future"
5
- end