buzzdata 0.0.4 → 0.0.5

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/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  .DS_Store
2
2
  buzzdata.yml
3
3
  spec/fixtures/unreadable.yml
4
+ samples/create_and_insert.rb
4
5
  *.gem
5
6
  .bundle
6
7
  .yardoc
data/README.md CHANGED
@@ -128,6 +128,56 @@ If your account has the ability to upload data to a dataset, you can do so like
128
128
 
129
129
  >> buzzdata.topics
130
130
 
131
+ ## Updating a Dataset
132
+
133
+ In some cases, it makes more sense to update your data on a row by row basis rather than importing a whole dataset at once.
134
+ For example, perhaps you made a GPS application and once an hour want to update it with your location. You could use the
135
+ row level API to insert only the new locations into the dataset.
136
+
137
+
138
+ ### Staging your Updates
139
+
140
+ Before you get started with the Row-Level API you'll have to familiarize yourself with the concept of staging your update.
141
+ Every time you upload a dataset to buzzdata, it creates a new version in the history. If you have an application that
142
+ updates the dataset frequently, you would end up with many, many versions that would pollute your dataset's history. To
143
+ get around this, we ask that you stage your updates before commiting them.
144
+
145
+ You can think of staging as setting aside the data that you want to commit later. You start by creating a stage with a
146
+ REST call. Then you add your updates to the stage whenever you want. Once you are ready to create a new version and
147
+ update the dataset, you call commit.
148
+
149
+ In the GPS example above, a good idea might be to stage a day's worth of updates, and then commit them at the end of the
150
+ day. It's up to you to decide when it makes sense for your dataset to be released as a new version!
151
+
152
+
153
+ ### Create a Stage
154
+
155
+ >> stage_id = buzzdata.create_stage('eviltrout/pets')
156
+
157
+ ### Stage an insertion
158
+
159
+ >> buzzdata.create_stage('eviltrout/pets', stage_id, ['col1', 'col2', 'col3'])
160
+
161
+ ### Stage an update
162
+
163
+ # where 1 is the row number we're updating.
164
+ >> buzzdata.create_stage('eviltrout/pets', stage_id, 1, ['col1', 'col2', 'col3'])
165
+
166
+ ### Stage a delete
167
+
168
+ # in this example, 2 is the row number we're removing
169
+ >> buzzdata.delete_row('eviltrout/pets', stage_id, 2)
170
+
171
+ ### Commit the Stage
172
+
173
+ # Create a new version of your dataset with the updates.
174
+ >> buzzdata.commit_stage('eviltrout/pets', stage_id)
175
+
176
+ ### Rollback the Stage
177
+
178
+ # In case you decide you don't want to create a new version
179
+ >> buzzdata.rollback_stage('eviltrout/pets', stage_id)
180
+
131
181
 
132
182
  ## Admin Level Functions
133
183
 
@@ -4,8 +4,8 @@ require 'json'
4
4
  require 'yaml'
5
5
 
6
6
  # Our code
7
- require 'buzzdata/error'
8
- require 'buzzdata/rest_helpers'
7
+ require File.join(File.dirname(__FILE__), 'buzzdata/error')
8
+ require File.join(File.dirname(__FILE__), 'buzzdata/rest_helpers')
9
9
 
10
10
  class Buzzdata
11
11
  YAML_ERRORS = [ArgumentError]
@@ -145,8 +145,37 @@ class Buzzdata
145
145
  result['user']
146
146
  end
147
147
 
148
+ def create_stage(dataset)
149
+ result = post_json(url_for("#{dataset}/stage"))
150
+ result['id']
151
+ end
152
+
153
+ def insert_rows(dataset, stage_id, rows)
154
+ check_success(post_json(url_for("#{dataset}/stage/#{stage_id}/rows"), rows: JSON.dump(rows)))
155
+ end
156
+
157
+ def update_row(dataset, stage_id, row_number, row)
158
+ check_success(put_json(url_for("#{dataset}/stage/#{stage_id}/rows/#{row_number}"), row: JSON.dump(row)))
159
+ end
160
+
161
+ def delete_row(dataset, stage_id, row_number)
162
+ check_success(delete_json(url_for("#{dataset}/stage/#{stage_id}/rows/#{row_number}")))
163
+ end
164
+
165
+ def commit_stage(dataset, stage_id)
166
+ check_success(post_json(url_for("#{dataset}/stage/#{stage_id}/commit")))
167
+ end
168
+
169
+ def rollback_stage(dataset, stage_id)
170
+ check_success(post_json(url_for("#{dataset}/stage/#{stage_id}/rollback")))
171
+ end
172
+
148
173
  private
149
174
 
175
+ def check_success(result)
176
+ raise Buzzdata::Error, "Error Updating row" if result['success'] != "OK"
177
+ end
178
+
150
179
  def param_blank?(obj, param)
151
180
  return (obj.nil? or obj[param].nil? or obj[param].empty?)
152
181
  end
@@ -11,7 +11,7 @@ module RestHelpers
11
11
 
12
12
  define_method(method) do |url, params={}|
13
13
  params['api_key'] = @api_key
14
- params = {:params => params} unless method == :post
14
+ params = {:params => params} unless [:post, :put].include?(method)
15
15
 
16
16
  RestClient.send(method, url, params) do |response, request, result, &block|
17
17
  case response.code
@@ -1,3 +1,3 @@
1
1
  class Buzzdata
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,16 @@
1
+ require '../lib/buzzdata'
2
+
3
+ if ARGV.size < 2
4
+ puts "Usage: ./append_data.rb dataset"
5
+ puts "Example: ./append_data.rb eviltrout/kittens-born-by-month col1 col2 col3 ..."
6
+ exit(0)
7
+ end
8
+
9
+ # Retrieve a Dataset's Details
10
+ buzzdata = Buzzdata.new
11
+ dataset = ARGV[0]
12
+
13
+ stage_id = buzzdata.create_stage(dataset)
14
+ buzzdata.insert_rows(dataset, stage_id, ARGV[1..-1])
15
+ buzzdata.commit_stage(dataset, stage_id)
16
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buzzdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-31 00:00:00.000000000 -05:00
12
+ date: 2012-02-15 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
17
- requirement: &2165160280 !ruby/object:Gem::Requirement
17
+ requirement: &2169934080 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.6.7
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2165160280
25
+ version_requirements: *2169934080
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &2165159640 !ruby/object:Gem::Requirement
28
+ requirement: &2169933560 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.6.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2165159640
36
+ version_requirements: *2169933560
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: mocha
39
- requirement: &2165159040 !ruby/object:Gem::Requirement
39
+ requirement: &2169932960 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 0.10.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2165159040
47
+ version_requirements: *2169932960
48
48
  description:
49
49
  email:
50
50
  - support@buzzdata.com
@@ -62,6 +62,7 @@ files:
62
62
  - lib/buzzdata/error.rb
63
63
  - lib/buzzdata/rest_helpers.rb
64
64
  - lib/buzzdata/version.rb
65
+ - samples/append_data.rb
65
66
  - samples/config/buzzdata.yml.sample
66
67
  - samples/dataset_overview.rb
67
68
  - samples/datasets/kittens_born.csv