gro_social 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b578a59a7d7c43b325f7044b7627907812a3c50
4
- data.tar.gz: 6e63949a4e84d4524c1b22e45408d8b8f774a90f
3
+ metadata.gz: a85919082f2b422d6af27ca25f65dfc708d02631
4
+ data.tar.gz: d019a4c597f24a24b50f53ebbf6cc1035df7e44a
5
5
  SHA512:
6
- metadata.gz: 7243e7cd5067cb31eeb8e7cc85d1ef3bdf13ae9304bc21cf80b3094d02d418fec2df7df7ca2c62c707563dd31214e911d587b1b4c3d765a76ef5789a16aac4b6
7
- data.tar.gz: 7cba85e96c4bfd8214cb2cf5fb7df5f5e47c4e50c0e79a2e94ad1db003a4f9bd119b1a5ac6924016f35934c59703acd7d99898f09964e025e879f305ba36c04c
6
+ metadata.gz: 75df8e90998b13945b6d666aef675f8cbd480d8cfc7db08ad8a2a77cd8cb5c2ccc7b89d466933d0c04e60a6dda36bef22fdb7b7ebe0e2dcc7ba27128231b2c57
7
+ data.tar.gz: 126f4b09d39a95a99e4a095831bcbd19318589a8fd7c095f8dd8bf65b1ee6b5a1ae530ad7e2e88f470f5d1ae0b32c74b8f280542c9c4984961e89c72a0c30f4c
data/README.md CHANGED
@@ -47,6 +47,12 @@ interact with the supported resources.
47
47
  There are two classes that you will work with in regards to users:
48
48
  `GroSocial::Users` and `GroSocial::User`. `GroSocial::Users` represents the
49
49
  class you will use to locate specific users or iterate over them.
50
+ `GroSocial::Users` can be treated like a Hash when it comes to accessing and
51
+ working with the `GroSocial::User` records.
52
+
53
+ #### Retrieval
54
+
55
+ Retrieval is keyed to the ID for the user you want to access.
50
56
 
51
57
  ```ruby
52
58
  user = GroSocial::Users[1234] # GroSocial::User
@@ -56,6 +62,26 @@ user.firstname # 'John'
56
62
  user.lastname # 'Doe'
57
63
  ```
58
64
 
65
+ #### Creation
66
+
67
+ The `<<` operation is used to both create and update records and its behavior
68
+ is based on whether the `GroSocial::User` being pushed in already has an ID
69
+ value set.
70
+
71
+ ```ruby
72
+ user = GroSocial::User.new(
73
+ firstname: 'John',
74
+ lastname: 'Doe',
75
+ email: 'johndoe@example.com',
76
+ password: 'secret123'
77
+ )
78
+ user.id # nil
79
+
80
+ GroSocial::Users << user
81
+
82
+ user.id # '12345'
83
+ ```
84
+
59
85
  ### Subscriptions
60
86
 
61
87
  TODO: Document the GroSocial::Subscription API
@@ -1,6 +1,7 @@
1
1
  module GroSocial
2
2
  class User
3
- attr_accessor :id, :firstname, :lastname, :email, :phone, :created, :custom1, :custom2, :custom3, :alertmessage
3
+ attr_accessor :id, :firstname, :lastname, :email, :phone, :created,
4
+ :custom1, :custom2, :custom3, :alertmessage, :password
4
5
 
5
6
  def initialize(attributes = {})
6
7
  attributes.each do |attr_name, value|
@@ -8,8 +8,25 @@ module GroSocial
8
8
  GroSocial::User.new(result['result']['user'])
9
9
  end
10
10
 
11
- def self.each(&block)
12
-
11
+ def self.<<(user)
12
+ options = { typhoeus: { body: {
13
+ firstname: user.firstname,
14
+ lastname: user.lastname,
15
+ email: user.email,
16
+ password: user.password,
17
+ phone: user.phone,
18
+ custom1: user.custom1,
19
+ custom2: user.custom2,
20
+ custom3: user.custom3,
21
+ alertmessage: user.alertmessage
22
+ }}}
23
+ result = GroSocial::Client.request('Users', :post, options)
24
+ user.id = result['result']['User']['id']
25
+ user
13
26
  end
27
+
28
+ # def self.each(&block)
29
+ #
30
+ # end
14
31
  end
15
32
  end
@@ -1,3 +1,3 @@
1
1
  module GroSocial
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -21,15 +21,43 @@ RSpec.describe GroSocial::Users do
21
21
  end
22
22
  end
23
23
 
24
- describe '.each' do
24
+ describe '.<<' do
25
25
  it 'responds' do
26
- expect(GroSocial::Users).to respond_to(:each)
26
+ expect(GroSocial::Users).to respond_to(:<<)
27
27
  end
28
28
 
29
- it 'returns GroSocial::User instances' do
30
- # GroSocial::Users.each do |user|
31
- # expect(user).to be_a_kind_of(GroSocial::User)
32
- # end
29
+ context 'with a fresh user' do
30
+ vcr_options = { cassette_name: 'GroSocial_Users/creating_a_user' }
31
+
32
+ let(:user) do
33
+ GroSocial::User.new(firstname: 'John',
34
+ lastname: 'Doe',
35
+ email: 'johndoe@example.org',
36
+ password: 'secret123',
37
+ phone: '(555) 123-4567')
38
+ end
39
+
40
+ it 'accepts and returns a GroSocial::User', vcr: vcr_options do
41
+ expect(GroSocial::Users << user).to be_a(GroSocial::User)
42
+ end
43
+
44
+ it 'updates the :id field', vcr: vcr_options do
45
+ expect(user.id).to be_nil
46
+ GroSocial::Users << user
47
+ expect(user.id).to_not be_nil
48
+ end
33
49
  end
34
50
  end
51
+
52
+ # describe '.each' do
53
+ # it 'responds' do
54
+ # expect(GroSocial::Users).to respond_to(:each)
55
+ # end
56
+ #
57
+ # it 'returns GroSocial::User instances' do
58
+ # # GroSocial::Users.each do |user|
59
+ # # expect(user).to be_a_kind_of(GroSocial::User)
60
+ # # end
61
+ # end
62
+ # end
35
63
  end
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://apidev.grosocial.com/users?key=<API_KEY>&p=<API_PASSWORD>
6
+ body:
7
+ encoding: UTF-8
8
+ string: alertmessage=&custom1=&custom2=&custom3=&email=johndoe%40example.org&firstname=John&lastname=Doe&password=secret123&phone=%28555%29%20123-4567
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Date:
18
+ - Mon, 09 Feb 2015 06:29:11 GMT
19
+ Server:
20
+ - Apache/2.2.14 (Ubuntu)
21
+ Set-Cookie:
22
+ - CAKEPHP=fa3qh0ie5k6u1bkd0c4f4pkjg2; expires=Mon, 09-Feb-2015 09:49:12 GMT;
23
+ path=/; secure
24
+ P3p:
25
+ - CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
26
+ Pragma:
27
+ - no-cache
28
+ Cache-Control:
29
+ - no-store, no-cache, max-age=0, must-revalidate
30
+ Content-Length:
31
+ - '81'
32
+ Content-Type:
33
+ - text/x-json
34
+ body:
35
+ encoding: UTF-8
36
+ string: '{"result":{"http_status":{"code":201,"message":"Created"},"User":{"id":"20712"}}}'
37
+ http_version:
38
+ recorded_at: Mon, 09 Feb 2015 06:29:12 GMT
39
+ recorded_with: VCR 2.9.3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gro_social
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Thompson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-06 00:00:00.000000000 Z
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -172,6 +172,7 @@ files:
172
172
  - vcr_cassettes/GroSocial_Client/_request/with_options_to_GET_all_Users/returns_a_parsed_JSON_response.yml
173
173
  - vcr_cassettes/GroSocial_Users/_/returns_a_GroSocial_User_when_one_exists.yml
174
174
  - vcr_cassettes/GroSocial_Users/_/returns_nil_when_a_User_does_not_exist.yml
175
+ - vcr_cassettes/GroSocial_Users/creating_a_user.yml
175
176
  homepage: https://github.com/BaseCampOps/gro_social
176
177
  licenses:
177
178
  - MIT
@@ -211,3 +212,4 @@ test_files:
211
212
  - vcr_cassettes/GroSocial_Client/_request/with_options_to_GET_all_Users/returns_a_parsed_JSON_response.yml
212
213
  - vcr_cassettes/GroSocial_Users/_/returns_a_GroSocial_User_when_one_exists.yml
213
214
  - vcr_cassettes/GroSocial_Users/_/returns_nil_when_a_User_does_not_exist.yml
215
+ - vcr_cassettes/GroSocial_Users/creating_a_user.yml