buzzdata 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # BuzzData Ruby Client Library
2
2
 
3
- The BuzzData Ruby Client Library is a simple wrapper for the BuzzData HTTP API that allows you to easily interact with datasets on BuzzData.
3
+ The BuzzData Ruby Client Library is a simple wrapper for the [BuzzData HTTP API](http://buzzdata.com/faq/buzzdata-api) that allows you to easily interact with datasets on BuzzData.
4
4
 
5
5
  ## Example
6
6
 
@@ -10,12 +10,12 @@ The BuzzData Ruby Client Library is a simple wrapper for the BuzzData HTTP API t
10
10
  buzzdata = Buzzdata.new('YOUR_API_KEY')
11
11
 
12
12
  # Create a Dataset
13
- dataset = buzzdata.create_dataset(:username => 'eviltrout',
14
- :name => "My Awesome Dataset!",
15
- :public => false,
16
- :readme => "This is my awesome dataset",
17
- :license => 'cc0',
18
- :topics => ['testing-buzzdata'])
13
+ dataset = buzzdata.create_dataset(username: 'eviltrout',
14
+ name: "My Awesome Dataset!",
15
+ public: false,
16
+ readme: "This is my awesome dataset",
17
+ license: 'cc0',
18
+ topics: ['testing-buzzdata'])
19
19
 
20
20
  # Upload some data
21
21
  buzzdata.upload(dataset['id'], File.new('datasets/celebrities.csv'), 'My first dataset!')
@@ -75,12 +75,12 @@ You can retrieve a list of uploaded versions of a dataset by calling `dataset_hi
75
75
 
76
76
  You can use the `create_dataset` method to create a new dataset. All fields are required:
77
77
 
78
- >> ds = buzzdata.create_dataset(:username => 'eviltrout',
79
- :name => "My Awesome Dataset!",
80
- :public => false,
81
- :readme => "This is my awesome dataset",
82
- :license => 'cc0',
83
- :topics => ['testing-buzzdata'])
78
+ >> ds = buzzdata.create_dataset(username: 'eviltrout',
79
+ name: "My Awesome Dataset!",
80
+ public: false,
81
+ readme: "This is my awesome dataset",
82
+ license: 'cc0',
83
+ topics: ['testing-buzzdata'])
84
84
 
85
85
  >> puts ds['id'] # outputs eviltrout/my-awesome-dataset
86
86
 
@@ -127,6 +127,16 @@ If your account has the ability to upload data to a dataset, you can do so like
127
127
  ### Get a list of usable Topics
128
128
 
129
129
  >> buzzdata.topics
130
+
131
+
132
+ ## Admin Level Functions
133
+
134
+ The following functions can only be used if your API key has been granted admin access:
135
+
136
+
137
+ ### Create a user
138
+
139
+ >> buzzdata.create_user(username: 'eviltrout_jr', email: 'eviltroutjr@buzzdata.com', password: 'aSECUREp4ssword')
130
140
 
131
141
 
132
142
  Copyright © 2011 [BuzzData](http://buzzdata.com/), released under the MIT license
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_runtime_dependency('rest-client', '~> 1.6.7')
22
22
  s.add_development_dependency('rspec', '~> 2.6.0')
23
+ s.add_development_dependency('mocha', '~> 0.10.0')
23
24
  end
@@ -135,6 +135,16 @@ class Buzzdata
135
135
  result['dataset']
136
136
  end
137
137
 
138
+ def create_user(attributes)
139
+ raise Buzzdata::Error, "Missing attributes" if attributes.nil?
140
+ raise Buzzdata::Error, "Username is required" if param_blank?(attributes, :username)
141
+ raise Buzzdata::Error, "Email is required" if param_blank?(attributes, :email)
142
+ raise Buzzdata::Error, "Password is required" if param_blank?(attributes, :password)
143
+
144
+ result = post_json(url_for("users"), :user => attributes)
145
+ result['user']
146
+ end
147
+
138
148
  private
139
149
 
140
150
  def param_blank?(obj, param)
@@ -1,3 +1,3 @@
1
1
  class Buzzdata
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -5,15 +5,6 @@ require 'securerandom'
5
5
 
6
6
  class Buzzdata
7
7
  describe Buzzdata do
8
- GENERIC_USER = 'eviltrout'
9
- NONEXISTENT_USER = 'missing'
10
- USER_WITH_PRIVATE_DATASET = 'jpmckinney'
11
- PUBLISH_SLEEP_INTERVAL = 5
12
-
13
- CLONABLE_DATASET = 'eviltrout/pets'
14
- NONEXISTENT_DATASET = 'missing/missing'
15
- PRIVATE_DATASET_BELONGING_TO_ANOTHER_USER = 'jpmckinney/private'
16
- UNPUBLISHED_DATASET_BELONGING_TO_ANOTHER_USER = 'jpmckinney/unpublished'
17
8
 
18
9
  def fixture_path(basename)
19
10
  File.expand_path File.dirname(__FILE__) + '/fixtures/' + basename
@@ -54,5 +45,44 @@ class Buzzdata
54
45
  expect{Buzzdata.new nil, :config_file => fixture_path('missing_api_key.yml')}.to raise_error(Buzzdata::Error, /API key missing/)
55
46
  end
56
47
  end
48
+
49
+ describe '#valid_credentials' do
50
+
51
+ before do
52
+ @buzzdata = Buzzdata.new nil, :config_file => fixture_path('custom.yml')
53
+ end
54
+
55
+ describe '#create_user' do
56
+
57
+ it 'posts the json when all params are present' do
58
+ @buzzdata.expects(:post_json).once.returns('user' => {})
59
+ @buzzdata.create_user(username: 'eviltrout', password: 'top_secret', email: 'eviltrout@buzzdata.com')
60
+ end
61
+
62
+ describe '#failing' do
63
+ before do
64
+ @buzzdata.expects(:post_json).never
65
+ end
66
+
67
+ it 'raises an exception when the username is missing' do
68
+ expect { @buzzdata.create_user(password: 'top_secret', email: 'eviltrout@buzzdata.com') }.to
69
+ raise_error(Buzzdata::Error, /Username is required/)
70
+ end
71
+
72
+ it 'raises an exception when the password is missing' do
73
+ expect { @buzzdata.create_user(username: 'eviltrout', email: 'eviltrout@buzzdata.com') }.to
74
+ raise_error(Buzzdata::Error, /Password is required/)
75
+ end
76
+
77
+ it 'raises an exception when the email is missing' do
78
+ expect { @buzzdata.create_user(username: 'eviltrout', password: 'top_secret') }.to
79
+ raise_error(Buzzdata::Error, /Email is required/)
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+
57
87
  end
58
88
  end
@@ -1,3 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'rspec'
3
3
  require File.dirname(__FILE__) + '/../lib/buzzdata'
4
+
5
+ require 'mocha'
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with :mocha
9
+ end
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.3
4
+ version: 0.0.4
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: 2011-12-05 00:00:00.000000000 -05:00
12
+ date: 2012-01-31 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: &2155951100 !ruby/object:Gem::Requirement
17
+ requirement: &2165160280 !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: *2155951100
25
+ version_requirements: *2165160280
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &2155947540 !ruby/object:Gem::Requirement
28
+ requirement: &2165159640 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,7 +33,18 @@ dependencies:
33
33
  version: 2.6.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2155947540
36
+ version_requirements: *2165159640
37
+ - !ruby/object:Gem::Dependency
38
+ name: mocha
39
+ requirement: &2165159040 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 0.10.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2165159040
37
48
  description:
38
49
  email:
39
50
  - support@buzzdata.com