geostellar_client 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: 688b9bfbd3b286b380fbff15db90c8e742ab44de
4
- data.tar.gz: 84935065f7c75b5f15422bf3e9faeabe3b2219ee
3
+ metadata.gz: 1791a78e5924e88bb802f6a936664411e97aa0a3
4
+ data.tar.gz: ee1492b2c1562dd341794541e08f08f72a3cd4bb
5
5
  SHA512:
6
- metadata.gz: 48ba81ebbe258cdec59d553e68296c3b5cad9fabb4873451326a56dbf8e655da97b581f8e2133c7c6818a328968c38d4fb58171e59af131a115e07ca600e6f1d
7
- data.tar.gz: 1413d48e7a86d5301979ad3eee61d1569a8805da474f22115645ad771933e97d6c412f0c048126a75b5126306db1cf4b7dc77c9372940d39f706e10538ad7585
6
+ metadata.gz: d7bfc30cabe84773de22b860d4430f9934738b3017768d8f27fed85f5e58b34ef8a116e766ab4437ccf067c6ec8a9c6c22e1c731eb6d0daac4dc92a9e1462c2a
7
+ data.tar.gz: d7eddc7475ac0875ced1b711ffe8b5181f11c146cc4ac0b9ad0bc587f25e5a64c6b0ab95350abf339c2d2c7c224990b93090fb84243f24c7e575d6488a10855c
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  spec/credentials.yml
11
+ *.gem
data/README.md CHANGED
@@ -24,14 +24,10 @@ Or install it yourself as:
24
24
  Configure the client with your API key:
25
25
 
26
26
  ```ruby
27
- GeostellarClient = YOURAPIKEY
27
+ GeostellarClient.api_key = YOURAPIKEY
28
28
  ```
29
29
 
30
- To fetch a user:
31
-
32
- ```ruby
33
- user = GeostellarClient::User.find(1)
34
- ```
30
+ ### User
35
31
 
36
32
  A user has the following attributes:
37
33
 
@@ -46,8 +42,38 @@ street_address_2, String
46
42
  city, String
47
43
  state, String
48
44
  zip_code, String
45
+ password, String
49
46
  ```
50
47
 
48
+ `password` is only used internally when talking to the user creation API. The User object returned by `User#create` has a password value of `nil`.
49
+
50
+ #### To fetch a user:
51
+
52
+ ```ruby
53
+ user = GeostellarClient::User.find(1)
54
+ ```
55
+
56
+ #### To create a user:
57
+
58
+ ```ruby
59
+ attributes = {
60
+ email: 'someemail@example.com',
61
+ password: 'password',
62
+ phone: '123456789',
63
+ first_name: 'Foo',
64
+ last_name: 'Bar',
65
+ street_address_1: '1 Street',
66
+ street_address_2: 'Address',
67
+ city: 'The City',
68
+ state: 'OR',
69
+ zip_code: '12345',
70
+ }
71
+
72
+ user = GeostellarClient::User.create(attributes)
73
+ ```
74
+
75
+ When successful this returns a `User` object. Otherwise a `GeostellarClient::UserCreationError` is raised, with the message returned by the API.
76
+
51
77
 
52
78
  ## Development
53
79
 
@@ -57,6 +83,14 @@ Then, run `rake rspec` to run the tests. You can also run `bin/console` for an i
57
83
 
58
84
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
85
 
86
+ ### To-do
87
+
88
+ - Update user
89
+ - Log-in
90
+ - Log-out
91
+ - PV Module, Incentive, Solar estimate models and API calls
92
+ - Address and monthly bill search
93
+
60
94
 
61
95
  ## Contributing
62
96
 
@@ -2,6 +2,7 @@ require 'virtus'
2
2
  require 'httparty'
3
3
  require 'geostellar_client/version'
4
4
  require 'geostellar_client/user'
5
+ require 'geostellar_client/exceptions'
5
6
 
6
7
  module GeostellarClient
7
8
  class << self
@@ -0,0 +1,5 @@
1
+ module GeostellarClient
2
+ class Error < StandardError; end
3
+
4
+ class UserCreationError < Error; end
5
+ end
@@ -13,6 +13,7 @@ module GeostellarClient
13
13
  attribute :city, String
14
14
  attribute :state, String
15
15
  attribute :zip_code, String
16
+ attribute :password, String
16
17
 
17
18
  def self.find(id)
18
19
  response = HTTParty.get(
@@ -22,6 +23,23 @@ module GeostellarClient
22
23
  new(JSON.parse(response.body))
23
24
  end
24
25
 
26
+ def self.create(attrs)
27
+ valid_attrs = User.new(attrs).attributes.reject { |k, v| v.nil? }
28
+ options = {
29
+ api_key: GeostellarClient.api_key,
30
+ body: { user: valid_attrs },
31
+ }
32
+
33
+ response = HTTParty.post(api_url, options)
34
+
35
+ if response.success?
36
+ new(response.parsed_response)
37
+ else
38
+ message = response["errors"].join(', ')
39
+ raise GeostellarClient::UserCreationError, message
40
+ end
41
+ end
42
+
25
43
  private
26
44
 
27
45
  def self.find_url(id)
@@ -1,3 +1,3 @@
1
1
  module GeostellarClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geostellar_client
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
  - JP Moral
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-11 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -169,6 +169,7 @@ files:
169
169
  - bin/setup
170
170
  - geostellar_client.gemspec
171
171
  - lib/geostellar_client.rb
172
+ - lib/geostellar_client/exceptions.rb
172
173
  - lib/geostellar_client/user.rb
173
174
  - lib/geostellar_client/version.rb
174
175
  homepage: https://github.com/jpmoral/geostellar_client