soda-ruby 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.mkd +1 -0
- data/lib/soda/client.rb +48 -94
- data/lib/soda/version.rb +1 -1
- metadata +9 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 03728c85703cdcf58f02132e9e296fc4600dcf55
|
4
|
+
data.tar.gz: 38e6f85d3d02a3189dd6176954233a450eea6dfc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ffab275d914f469e2c6292a3c2ecba5f72aa6ac9fe525f3665e2d78bd3009ee769d11ac0f12279ea102d8a76a215f51ad2c1d57ea53b9fc566513c38595a64e9
|
7
|
+
data.tar.gz: d5cf160a323314a370e9da4fd9fd0243f6e346231dc017127569973d48d396ef06c5fd70ebb3a88edd7af8e2102f42cd09de0897efb9d2d9173552d408fdd9da
|
data/CHANGELOG.mkd
CHANGED
data/lib/soda/client.rb
CHANGED
@@ -15,70 +15,19 @@ module SODA
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def get(resource, params = {})
|
18
|
-
|
19
|
-
path = resource_path(resource)
|
20
|
-
|
21
|
-
# Create our request
|
22
|
-
uri = URI.parse("https://#{@config[:domain]}#{path}?#{query}")
|
23
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
24
|
-
http.use_ssl = true
|
25
|
-
|
26
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
27
|
-
request.add_field("X-App-Token", @config[:app_token])
|
28
|
-
|
29
|
-
# Authenticate if we're supposed to
|
30
|
-
if @config[:username]
|
31
|
-
request.basic_auth @config[:username], @config[:password]
|
32
|
-
end
|
33
|
-
|
34
|
-
# BAM!
|
35
|
-
return handle_response(http.request(request))
|
18
|
+
connection(:get, resource, nil, params)
|
36
19
|
end
|
37
20
|
|
38
|
-
def post(resource, body =
|
39
|
-
|
40
|
-
path = resource_path(resource)
|
41
|
-
|
42
|
-
# Create our request
|
43
|
-
uri = URI.parse("https://#{@config[:domain]}#{path}?#{query}")
|
44
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
45
|
-
http.use_ssl = true
|
46
|
-
|
47
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
48
|
-
request.add_field("X-App-Token", @config[:app_token])
|
49
|
-
request.content_type = "application/json"
|
50
|
-
request.body = body.to_json
|
51
|
-
|
52
|
-
# Authenticate if we're supposed to
|
53
|
-
if @config[:username]
|
54
|
-
request.basic_auth @config[:username], @config[:password]
|
55
|
-
end
|
56
|
-
|
57
|
-
# BAM!
|
58
|
-
return handle_response(http.request(request))
|
21
|
+
def post(resource, body = nil, params = {})
|
22
|
+
connection(:post, resource, body, params)
|
59
23
|
end
|
60
24
|
|
61
|
-
def put(resource, body =
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
# Create our request
|
66
|
-
uri = URI.parse("https://#{@config[:domain]}#{path}?#{query}")
|
67
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
68
|
-
http.use_ssl = true
|
69
|
-
|
70
|
-
request = Net::HTTP::Put.new(uri.request_uri)
|
71
|
-
request.add_field("X-App-Token", @config[:app_token])
|
72
|
-
request.content_type = "application/json"
|
73
|
-
request.body = body.to_json
|
74
|
-
|
75
|
-
# Authenticate if we're supposed to
|
76
|
-
if @config[:username]
|
77
|
-
request.basic_auth @config[:username], @config[:password]
|
78
|
-
end
|
25
|
+
def put(resource, body = nil, params = {})
|
26
|
+
connection(:put, resource, body, params)
|
27
|
+
end
|
79
28
|
|
80
|
-
|
81
|
-
|
29
|
+
def delete(resource, body = nil, params = {})
|
30
|
+
connection(:delete, resource, body, params)
|
82
31
|
end
|
83
32
|
|
84
33
|
def upload_file(path, filename, params = {}, field = 'file', remote_filename = filename)
|
@@ -144,41 +93,6 @@ module SODA
|
|
144
93
|
return handle_response(http.request(request))
|
145
94
|
end
|
146
95
|
|
147
|
-
def delete(resource, body = "", params = {})
|
148
|
-
query = query_string(params)
|
149
|
-
|
150
|
-
# If we didn't get a full path, assume "/resource/"
|
151
|
-
if !resource.start_with?("/")
|
152
|
-
resource = "/resource/" + resource
|
153
|
-
end
|
154
|
-
|
155
|
-
# Create our request
|
156
|
-
uri = URI.parse("https://#{@config[:domain]}#{resource}.json?#{query}")
|
157
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
158
|
-
http.use_ssl = true
|
159
|
-
|
160
|
-
request = Net::HTTP::Delete.new(uri.request_uri)
|
161
|
-
request.add_field("X-App-Token", @config[:app_token])
|
162
|
-
request.content_type = "application/json"
|
163
|
-
request.body = body.to_json
|
164
|
-
|
165
|
-
# Authenticate if we're supposed to
|
166
|
-
if @config[:username]
|
167
|
-
request.basic_auth @config[:username], @config[:password]
|
168
|
-
end
|
169
|
-
|
170
|
-
# BAM!
|
171
|
-
response = http.request(request)
|
172
|
-
|
173
|
-
# Check our response code
|
174
|
-
if response.code != "200"
|
175
|
-
raise "Error querying \"#{uri.to_s}\": #{response.body}"
|
176
|
-
else
|
177
|
-
# Return a bunch of mashes
|
178
|
-
return response
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
96
|
private
|
183
97
|
def query_string(params)
|
184
98
|
# Create query string of escaped key, value pairs
|
@@ -220,5 +134,45 @@ module SODA
|
|
220
134
|
end
|
221
135
|
end
|
222
136
|
end
|
137
|
+
|
138
|
+
def connection(method = "Get", resource = nil, body = nil, params = {})
|
139
|
+
method = method.to_sym.capitalize
|
140
|
+
|
141
|
+
query = query_string(params)
|
142
|
+
|
143
|
+
path = resource_path(resource)
|
144
|
+
|
145
|
+
uri = URI.parse("https://#{@config[:domain]}#{path}?#{query}")
|
146
|
+
|
147
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
148
|
+
http.use_ssl = true
|
149
|
+
request = eval("Net::HTTP::#{method.capitalize}").new(uri.request_uri)
|
150
|
+
request.add_field("X-App-Token", @config[:app_token])
|
151
|
+
|
152
|
+
if method === :Post || :Put || :Delete
|
153
|
+
request.content_type = "application/json"
|
154
|
+
request.body = body.to_json
|
155
|
+
end
|
156
|
+
|
157
|
+
# Authenticate if we're supposed to
|
158
|
+
|
159
|
+
if @config[:username]
|
160
|
+
request.basic_auth @config[:username], @config[:password]
|
161
|
+
end
|
162
|
+
|
163
|
+
if method === :Delete
|
164
|
+
response = http.request(request)
|
165
|
+
# Check our response code
|
166
|
+
if response.code != "200"
|
167
|
+
raise "Error querying \"#{uri.to_s}\": #{response.body}"
|
168
|
+
else
|
169
|
+
# Return a bunch of mashes
|
170
|
+
return response
|
171
|
+
end
|
172
|
+
else
|
173
|
+
return handle_response(http.request(request))
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
223
177
|
end
|
224
178
|
end
|
data/lib/soda/version.rb
CHANGED
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soda-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Chris Metcalf
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-01-09 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: hashie
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: A simple wrapper for SODA 2.0
|
@@ -41,26 +38,25 @@ files:
|
|
41
38
|
- README.mkd
|
42
39
|
homepage: http://github.com/socrata/soda-ruby
|
43
40
|
licenses: []
|
41
|
+
metadata: {}
|
44
42
|
post_install_message:
|
45
43
|
rdoc_options: []
|
46
44
|
require_paths:
|
47
45
|
- lib
|
48
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
47
|
requirements:
|
51
|
-
- -
|
48
|
+
- - '>='
|
52
49
|
- !ruby/object:Gem::Version
|
53
50
|
version: '0'
|
54
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
52
|
requirements:
|
57
|
-
- -
|
53
|
+
- - '>='
|
58
54
|
- !ruby/object:Gem::Version
|
59
55
|
version: 1.3.6
|
60
56
|
requirements: []
|
61
57
|
rubyforge_project: soda-ruby
|
62
|
-
rubygems_version:
|
58
|
+
rubygems_version: 2.0.3
|
63
59
|
signing_key:
|
64
|
-
specification_version:
|
60
|
+
specification_version: 4
|
65
61
|
summary: Ruby for SODA 2.0
|
66
62
|
test_files: []
|