parse-ruby-client 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +2 -1
- data/Gemfile +4 -6
- data/Gemfile.lock +18 -18
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/example.rb +2 -1
- data/fixtures/vcr_cassettes/test_batch_update_nils_delete_keys.yml +57 -0
- data/fixtures/vcr_cassettes/test_empty_response.yml +72 -0
- data/fixtures/vcr_cassettes/test_get_missing.yml +95 -38
- data/fixtures/vcr_cassettes/test_image_file_associate_with_object.yml +2089 -0
- data/fixtures/vcr_cassettes/test_image_file_save.yml +1928 -0
- data/fixtures/vcr_cassettes/test_object_id.yml +56 -0
- data/fixtures/vcr_cassettes/test_reset_password.yml +109 -0
- data/fixtures/vcr_cassettes/test_retries.yml +357 -0
- data/fixtures/vcr_cassettes/test_retries_404.yml +72 -0
- data/fixtures/vcr_cassettes/test_retries_404_correct.yml +72 -0
- data/fixtures/vcr_cassettes/test_retries_json_error.yml +357 -0
- data/fixtures/vcr_cassettes/test_retries_server_error.yml +357 -0
- data/fixtures/vcr_cassettes/test_server_update.yml +248 -191
- data/fixtures/vcr_cassettes/test_user_login.yml +276 -0
- data/fixtures/vcr_cassettes/test_xget.yml +280 -0
- data/lib/faraday/better_retry.rb +94 -0
- data/lib/faraday/extended_parse_json.rb +39 -0
- data/lib/faraday/get_method_override.rb +32 -0
- data/lib/parse-ruby-client.rb +9 -9
- data/lib/parse/batch.rb +2 -3
- data/lib/parse/client.rb +72 -161
- data/lib/parse/cloud.rb +2 -1
- data/lib/parse/datatypes.rb +6 -1
- data/lib/parse/error.rb +7 -3
- data/lib/parse/installation.rb +18 -0
- data/lib/parse/model.rb +2 -1
- data/lib/parse/object.rb +7 -1
- data/lib/parse/protocol.rb +10 -0
- data/lib/parse/push.rb +3 -0
- data/lib/parse/query.rb +5 -2
- data/lib/parse/user.rb +1 -0
- data/lib/parse/util.rb +2 -0
- data/parse-ruby-client.gemspec +35 -15
- data/test/helper.rb +55 -1
- data/test/middleware/better_retry_test.rb +57 -0
- data/test/middleware/extend_parse_json_test.rb +55 -0
- data/test/test_client.rb +78 -28
- data/test/test_datatypes.rb +14 -0
- data/test/test_object.rb +16 -0
- metadata +39 -34
- data/lib/parse/http_client.rb +0 -84
data/lib/parse/http_client.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
module Parse
|
2
|
-
class HttpClient
|
3
|
-
class TimeoutError < StandardError; end
|
4
|
-
|
5
|
-
attr_accessor :base_url, :headers
|
6
|
-
|
7
|
-
def initialize(base_url=nil, headers = {})
|
8
|
-
@base_url = base_url
|
9
|
-
@headers = headers
|
10
|
-
end
|
11
|
-
|
12
|
-
def build_query(hash)
|
13
|
-
hash.to_a.map{|k, v| "#{k}=#{v}"}.join('&')
|
14
|
-
end
|
15
|
-
|
16
|
-
def request(method, uri, headers, options)
|
17
|
-
NotImplementedError.new("Subclass responsibility")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class NetHttpClient < HttpClient
|
22
|
-
class NetHttpResponseWrapper
|
23
|
-
def initialize(response) @response = response end
|
24
|
-
def status() @response.code.to_i end
|
25
|
-
def body() @response.read_body end
|
26
|
-
end
|
27
|
-
|
28
|
-
def request(method, uri, headers, options)
|
29
|
-
request_class = eval("Net::HTTP::#{method.to_s.capitalize}")
|
30
|
-
uri = "#{uri}?#{options[:query]}" if options[:query]
|
31
|
-
request = request_class.new(uri, @headers.dup.update(headers))
|
32
|
-
request.body = options[:data] if options.has_key?(:data)
|
33
|
-
NetHttpResponseWrapper.new(
|
34
|
-
@client.start do
|
35
|
-
@client.request(request)
|
36
|
-
end
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
def base_url=(url)
|
41
|
-
@base_url = url
|
42
|
-
@client = Net::HTTP.new(@base_url.sub('https://', ''), 443)
|
43
|
-
@client.use_ssl = true
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class PatronHttpClient < HttpClient
|
48
|
-
def initialize(base_url=nil, headers = {})
|
49
|
-
super
|
50
|
-
@session = Patron::Session.new
|
51
|
-
@session.timeout = 30
|
52
|
-
@session.connect_timeout = 30
|
53
|
-
@session.headers.update(@headers)
|
54
|
-
end
|
55
|
-
|
56
|
-
def build_query(hash)
|
57
|
-
Patron::Util.build_query_pairs_from_hash(hash).join('&')
|
58
|
-
end
|
59
|
-
|
60
|
-
def request(method, uri, headers, options)
|
61
|
-
@session.request(method, uri, headers, options)
|
62
|
-
rescue Patron::TimeoutError => e
|
63
|
-
raise HttpClient::TimeoutError.new(e)
|
64
|
-
end
|
65
|
-
|
66
|
-
def base_url
|
67
|
-
@session.base_url
|
68
|
-
end
|
69
|
-
|
70
|
-
def base_url=(url)
|
71
|
-
@session.base_url = url
|
72
|
-
end
|
73
|
-
|
74
|
-
def headers
|
75
|
-
@session.headers
|
76
|
-
end
|
77
|
-
|
78
|
-
def headers=(hash)
|
79
|
-
@session.headers = hash
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
DEFAULT_HTTP_CLIENT = defined?(JRUBY_VERSION) ? NetHttpClient : PatronHttpClient
|
84
|
-
end
|