awesm 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -10,18 +10,14 @@ explanation :)
10
10
 
11
11
  In your Gemfile:
12
12
 
13
- ```ruby
14
- gem 'awesm'
15
- ```
13
+ gem 'awesm'
16
14
 
17
15
  And in your code:
18
16
 
19
- ```ruby
20
- Awesm.subscription_key = 'sub-xxxxxx'
21
- Awesm.application_key = 'app-xxxxxx'
22
- project = Awesm::Project.create(:name => 'Totally Awe.sm!')
23
- project.api_key # => '1234567890abcdefghijklmnopqrstuvwxyz'
24
- ```
17
+ Awesm.subscription_key = 'sub-xxxxxx'
18
+ Awesm.application_key = 'app-xxxxxx'
19
+ project = Awesm::Project.create(:name => 'TotallyAwesm')
20
+ project.api_key # => '1234567890abcdefghijklmnopqrstuvwxyz'
25
21
 
26
22
  ## Contributing ##
27
23
 
@@ -1,9 +1,9 @@
1
- require 'awesm/version'
2
-
3
1
  require 'httparty'
4
2
  require 'json'
5
3
  require 'hashie'
6
- require 'ruby-debug'
4
+
5
+ require 'awesm/version'
6
+ require 'awesm/project'
7
7
 
8
8
  module Awesm
9
9
  def self.subscription_key=(key)
@@ -21,14 +21,4 @@ module Awesm
21
21
  def self.application_key
22
22
  @@application_key
23
23
  end
24
-
25
- class Project < Hashie::Mash
26
- include HTTParty
27
- base_uri 'http://api.awe.sm/projects'
28
-
29
- def self.create(attributes)
30
- response = post('/new', :query => { :application_key => Awesm.application_key, :subscription_key => Awesm.subscription_key, :json => attributes.to_json })
31
- new(response['response']['project'])
32
- end
33
- end
34
24
  end
@@ -0,0 +1,15 @@
1
+ module Awesm
2
+ class Project < Hashie::Mash
3
+ include HTTParty
4
+ base_uri 'http://api.awe.sm/projects'
5
+
6
+ def self.create(attributes)
7
+ response = post('/new', :query => { :application_key => Awesm.application_key, :subscription_key => Awesm.subscription_key, :json => attributes.to_json })
8
+ if response.has_key?("error")
9
+ nil
10
+ else
11
+ new(response['response']['project'])
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Awesm
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe Awesm::Project do
4
+ let(:json_response) do
5
+ {
6
+ "request" => {
7
+ "application_key" => "app-xxxxxx",
8
+ "json" => "{\"name\" =>\"TotallyAwesomeProject\"}",
9
+ "method" => "new",
10
+ "object" => "project",
11
+ "subscription_key" => "sub-xxxxxx"
12
+ },
13
+ "response" => {
14
+ "project" => {
15
+ "admins" => [],
16
+ "api_key" => "6xxxxxxxxx58xx0xxx74xx3x76xx83x6x34xx48x7xxxx55x167037818d65x66x",
17
+ "created_at" => "2011-10-25 00:43:49",
18
+ "default_domain" => "awe.sm",
19
+ "domains" => [],
20
+ "name" => "myNewProject",
21
+ "sharers" => [],
22
+ "updated_at" => "2011-10-25 00:43:49",
23
+ "viewers" => []
24
+ }
25
+ }
26
+ }.to_json
27
+ end
28
+
29
+ let(:json_error_response) do
30
+ {
31
+ "request" => {
32
+ "application_key" => "app-xxxxxx",
33
+ "json" => "{\"name\" =>\"ExistingAwesomeProject\"}",
34
+ "method" => "new",
35
+ "object" => "project",
36
+ "subscription_key" => "sub-xxxxxx"
37
+ },
38
+ "error" => {
39
+ "code"=>10001,
40
+ "message"=>"Project name already exists (not necessarily in your subscription). Please choose another."
41
+ }
42
+ }.to_json
43
+ end
44
+
45
+ before do
46
+ Awesm.subscription_key = 'sub-xxxxxx'
47
+ Awesm.application_key = 'app-xxxxxx'
48
+ stub_request(:post, "http://api.awe.sm/projects/new?json=%7B%22name%22:%22TotallyAwesomeProject%22%7D&subscription_key=sub-xxxxxx&application_key=app-xxxxxx").
49
+ to_return(:status => 200, :body => json_response, :headers => { 'Content-Type' => 'application/json;charset=utf-8' })
50
+ stub_request(:post, "http://api.awe.sm/projects/new?json=%7B%22name%22:%22ExistingAwesomeProject%22%7D&subscription_key=sub-xxxxxx&application_key=app-xxxxxx").
51
+ to_return(:status => 400, :body => json_error_response, :headers => { 'Content-Type' => 'application/json;charset=utf-8' })
52
+ end
53
+ after do
54
+ Awesm.subscription_key = nil
55
+ Awesm.application_key = nil
56
+ end
57
+
58
+ context '.create' do
59
+ context 'when an error occurs' do
60
+ it 'returns nil' do
61
+ project = Awesm::Project.create(:name => "ExistingAwesomeProject")
62
+ project.should == nil
63
+ end
64
+ end
65
+
66
+ context 'when successful' do
67
+ it 'returns an Awesm::Project' do
68
+ project = Awesm::Project.create(:name => "TotallyAwesomeProject")
69
+ project.should be_an_instance_of(Awesm::Project)
70
+ end
71
+ end
72
+
73
+ it 'posts to the awe.sm project creation api properly' do
74
+ Awesm::Project.create({ :name => "TotallyAwesomeProject" })
75
+
76
+ a_request(:post, "http://api.awe.sm/projects/new").
77
+ with(:query => {:subscription_key => "sub-xxxxxx", :application_key => "app-xxxxxx", :json => { "name" => "TotallyAwesomeProject" }.to_json }).
78
+ should have_been_made.once
79
+ end
80
+ end
81
+
82
+ describe '#api_key' do
83
+ it 'returns the awe.sm api_key' do
84
+ project = Awesm::Project.create({ :name => "TotallyAwesomeProject" })
85
+ project.api_key.should == '6xxxxxxxxx58xx0xxx74xx3x76xx83x6x34xx48x7xxxx55x167037818d65x66x'
86
+ end
87
+ end
88
+ end
@@ -20,63 +20,3 @@ describe Awesm do
20
20
  Awesm.application_key = nil
21
21
  end
22
22
  end
23
-
24
- describe Awesm::Project do
25
- let(:json_response) do
26
- {
27
- "request" => {
28
- "application_key" => "app-xxxxxx",
29
- "json" => "{\"name\" =>\"Totally Awesome Project\"}",
30
- "method" => "new",
31
- "object" => "project",
32
- "subscription_key" => "sub-xxxxxx"
33
- },
34
- "response" => {
35
- "project" => {
36
- "admins" => [],
37
- "api_key" => "6xxxxxxxxx58xx0xxx74xx3x76xx83x6x34xx48x7xxxx55x167037818d65x66x",
38
- "created_at" => "2011-10-25 00:43:49",
39
- "default_domain" => "awe.sm",
40
- "domains" => [],
41
- "name" => "myNewProject",
42
- "sharers" => [],
43
- "updated_at" => "2011-10-25 00:43:49",
44
- "viewers" => []
45
- }
46
- }
47
- }.to_json
48
- end
49
-
50
- before do
51
- Awesm.subscription_key = 'sub-xxxxxx'
52
- Awesm.application_key = 'app-xxxxxx'
53
- stub_request(:post, "http://api.awe.sm/projects/new?json=%7B%22name%22:%22Totally%20Awesome%20Project%22%7D&subscription_key=sub-xxxxxx&application_key=app-xxxxxx").
54
- to_return(:status => 200, :body => json_response, :headers => { 'Content-Type' => 'application/json;charset=utf-8' })
55
- end
56
- after do
57
- Awesm.subscription_key = nil
58
- Awesm.application_key = nil
59
- end
60
-
61
- context '.create' do
62
- it 'returns an Awesm::Project' do
63
- project = Awesm::Project.create(:name => "Totally Awesome Project")
64
- project.should be_an_instance_of(Awesm::Project)
65
- end
66
-
67
- it 'posts to the awe.sm project creation api properly' do
68
- Awesm::Project.create({ :name => "Totally Awesome Project" })
69
-
70
- a_request(:post, "http://api.awe.sm/projects/new").
71
- with(:query => {:subscription_key => "sub-xxxxxx", :application_key => "app-xxxxxx", :json => { "name" => "Totally Awesome Project" }.to_json }).
72
- should have_been_made.once
73
- end
74
- end
75
-
76
- describe '#api_key' do
77
- it 'returns the awe.sm api_key' do
78
- project = Awesm::Project.create({ :name => "Totally Awesome Project" })
79
- project.api_key.should == '6xxxxxxxxx58xx0xxx74xx3x76xx83x6x34xx48x7xxxx55x167037818d65x66x'
80
- end
81
- end
82
- end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sathya Sekaran
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-11-18 00:00:00 Z
19
+ date: 2011-11-30 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rake
@@ -177,7 +177,9 @@ files:
177
177
  - Rakefile
178
178
  - awesm.gemspec
179
179
  - lib/awesm.rb
180
+ - lib/awesm/project.rb
180
181
  - lib/awesm/version.rb
182
+ - spec/awesm/project_spec.rb
181
183
  - spec/awesm_spec.rb
182
184
  - spec/spec_helper.rb
183
185
  homepage: http://github.com/sfsekaran/awesm
@@ -214,5 +216,6 @@ signing_key:
214
216
  specification_version: 3
215
217
  summary: Totally awe.sm!
216
218
  test_files:
219
+ - spec/awesm/project_spec.rb
217
220
  - spec/awesm_spec.rb
218
221
  - spec/spec_helper.rb