soda-ruby 0.2.12 → 0.2.13

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 465ea1cbe79b189bc29e2798e6e907e677a21963
4
+ data.tar.gz: d1c223e502052c9a07e34c95298ffdc237660b4c
5
+ SHA512:
6
+ metadata.gz: db13c563d0055fcfdaa4ded0d8bf56874e0346085b0b10a2ec4165d633c6d292c0abee3f334940629d416f2e7f77b4a52d5e1545b71583a808a78739575ced2a
7
+ data.tar.gz: 4a09101c6259b561b5ade89efc45d2ed39ee8e5231d2e212efa982174848c58832594a43d56ca6e592ccfeba0a8b5946b979eb439ce4cde978949266201ad6bb
@@ -8,3 +8,4 @@
8
8
  0.2.10 - Removing a nesting limit that we missed
9
9
  0.2.11 - We weren't properly handling an empty payload response
10
10
  0.2.12 - Added a global option to disable SSL checking from https://github.com/socrata/soda-ruby/pull/7
11
+ 0.2.13 - Added a global :timeout option to override the default Net:HTTP timeout, and accepting 202 as an "OK" response code, which should only occur during import.
@@ -0,0 +1,35 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Socrata < OmniAuth::Strategies::OAuth2
6
+ option :name, "socrata"
7
+
8
+ option :client_options, {
9
+ :site => "https://opendata.socrata.com",
10
+ :authorize_url => "http://opendata.socrata.com/oauth/authorize",
11
+ :provider_ignores_state => true
12
+ }
13
+
14
+ # Sets the UID from the user's info
15
+ uid{ raw_info['id'] }
16
+
17
+ info do
18
+ {
19
+ :name => raw_info['name'],
20
+ :email => raw_info['email']
21
+ }
22
+ end
23
+
24
+ extra do
25
+ {
26
+ 'raw_info' => raw_info
27
+ }
28
+ end
29
+
30
+ def raw_info
31
+ @raw_info ||= access_token.get('/api/users/current.json').parsed
32
+ end
33
+ end
34
+ end
35
+ end
@@ -159,7 +159,7 @@ module SODA
159
159
 
160
160
  def handle_response(response)
161
161
  # Check our response code
162
- if response.code != "200"
162
+ if !["200", "202"].include? response.code
163
163
  raise "Error in request: #{response.body}"
164
164
  else
165
165
  if response.body.nil? || response.body.empty?
@@ -223,6 +223,9 @@ module SODA
223
223
  if @config[:ignore_ssl]
224
224
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
225
225
  end
226
+ if @config[:timeout]
227
+ http.read_timeout = @config[:timeout]
228
+ end
226
229
  http
227
230
  end
228
231
 
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # A Ruby client to the Socrata SmartUpdate API
4
+ #
5
+ # For more details, check out http://socrata.github.io/soda-ruby
6
+ #
7
+
8
+ require 'soda/client'
9
+
10
+ module SODA
11
+ class SmartUpdate
12
+ ##
13
+ #
14
+ # Creates a new SmartUpdate client.
15
+ #
16
+ # * +config+ - A hash of the options to initialize the client with. The options are the same as SODA::Client
17
+ #
18
+ # == Config Options
19
+ #
20
+ # * +:domain+ - The domain you want to access
21
+ # * +:username+ - Your Socrata username (optional, only necessary for modifying data)
22
+ # * +:password+ - Your Socrata password (optional, only necessary for modifying data)
23
+ # * +:app_token+ - Your Socrata application token (register at http://dev.socrata.com/register)
24
+ # * +:ignore_ssl+ - Ignore ssl errors (defaults to false)
25
+ #
26
+ # Returns a SODA::Client instance.
27
+ #
28
+ # == Example
29
+ #
30
+ # client = SODA::Client.new({ :domain => "data.agency.gov", :app_token => "CGxarwoQlgQSev4zyUh5aR5J3" })
31
+ #
32
+ def initialize(config = {})
33
+ @config = config.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
34
+ @client = SODA::Client.new(@config)
35
+
36
+ # Fetch version and blocksize information from the service
37
+ @blocksize = @client.get("/datasync/version.json")["max-block-size"]
38
+ end
39
+
40
+ # Chunks a file for smart-updating and uploads it
41
+ def upload(uid, filename, options = {})
42
+ options = DEFAULT_OPTIONS.merge(options)
43
+
44
+ # Determine the file size, and ideal chunk size
45
+ filesize = File.size(filename)
46
+ blocks = (0..filesize).step(@blocksize).collect do |offset|
47
+ @client.post("/datasync/id/#{uid}",
48
+ IO.read(filename, @blocksize, offset)).blobId
49
+ end
50
+ return blocks
51
+ end
52
+
53
+ # Commits a set of chunks to be written
54
+ def commit(uid, filename, chunks)
55
+ @client.post("/datasync/id/#{uid}/commit", {:filename => filename, :chunks => chunks}).jobId
56
+ end
57
+
58
+ # Check on the status of a job
59
+ def check(uid, job_id)
60
+ @client.get("/datasync/id/#{uid}/status/#{job_id}", nil, nil)
61
+ end
62
+ end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module SODA
2
- VERSION = "0.2.12"
2
+ VERSION = "0.2.13"
3
3
  end
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.12
5
- prerelease:
4
+ version: 0.2.13
6
5
  platform: ruby
7
6
  authors:
8
7
  - Chris Metcalf
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-03-25 00:00:00.000000000 Z
11
+ date: 2015-01-15 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
@@ -33,34 +30,35 @@ executables: []
33
30
  extensions: []
34
31
  extra_rdoc_files: []
35
32
  files:
36
- - lib/soda/client.rb
37
- - lib/soda/version.rb
38
- - lib/soda.rb
39
- - LICENSE
40
33
  - CHANGELOG.mkd
34
+ - LICENSE
41
35
  - README.mkd
36
+ - lib/omniauth-socrata.rb
37
+ - lib/soda.rb
38
+ - lib/soda/client.rb
39
+ - lib/soda/smartupdate.rb
40
+ - lib/soda/version.rb
42
41
  homepage: http://github.com/socrata/soda-ruby
43
42
  licenses: []
43
+ metadata: {}
44
44
  post_install_message:
45
45
  rdoc_options: []
46
46
  require_paths:
47
47
  - lib
48
48
  required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
49
  requirements:
51
- - - ! '>='
50
+ - - ">="
52
51
  - !ruby/object:Gem::Version
53
52
  version: '0'
54
53
  required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
54
  requirements:
57
- - - ! '>='
55
+ - - ">="
58
56
  - !ruby/object:Gem::Version
59
57
  version: 1.3.6
60
58
  requirements: []
61
59
  rubyforge_project: soda-ruby
62
- rubygems_version: 1.8.23
60
+ rubygems_version: 2.2.2
63
61
  signing_key:
64
- specification_version: 3
62
+ specification_version: 4
65
63
  summary: Ruby for SODA 2.0
66
64
  test_files: []