ahub 0.0.3 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1dd53ca33d1f090cf62539d029b4eb07adb8591c
4
- data.tar.gz: 025c3061b2a858b1e4df1029a156aab41672a5f9
3
+ metadata.gz: 1199769f6a7e1fb2ab32dd7ce2264a2c8ffcea5d
4
+ data.tar.gz: 8ee41bb02b0f74642837b356b92e46bbf4497b71
5
5
  SHA512:
6
- metadata.gz: 5528bababcb56b065c9b88ed382bfc87ad55c6a962c80e927540d5a503ca90a31e0a27beafcf5cfb0aa6180f7a0442fc30f262f2e0726b4d987fd09853c3ecee
7
- data.tar.gz: e9c00719479dde3676e350522c6d5a5af44571678d4c50c09b48074c2c144e28c8fa92182d277ba89bfb6f3e1ac54c67a65c66182b295ea7340d09dc6306f832
6
+ metadata.gz: 95d65c938c31b9af559b64c8ec60b49ebd911c6e85d06057b00d897048eb86701d5ba74c44f704bf7a2dab22856f3e55e45b55aa940596029a1103a2d43b05da
7
+ data.tar.gz: 8f8fc405a53089a8638b2bd132471879cbc06f04a4cb3168b0bb8a7d5cd044cda0a35e220ccae23c39bd6648bdb7c05dd09a74994cfa9e4c4072c6d1a7523866
data/.env_example ADDED
@@ -0,0 +1,4 @@
1
+ AHUB_DEFAULT_PASSWORD=password
2
+ AHUB_ADMIN_USER=answerhub
3
+ AHUB_ADMIN_PASS=answerhub
4
+ AHUB_DOMIAN="http://localhost:8888"
data/.gitignore CHANGED
@@ -8,4 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .DS_Store
11
- *.gem
11
+ .env
data/README.md CHANGED
@@ -19,6 +19,12 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
+ By default, this gem will use the answer hub default connection credentials (answerhub/answerhub). You can override defaults by setting content in [a .env file like the example](https://github.com/abelmartin/ahub/blob/master/.env_example) and reference it like this for example:
23
+
24
+ ```bash
25
+ AHUB_ENV_FILE=~/workspace/.ahub_env irb
26
+ ```
27
+
22
28
  ## Development
23
29
 
24
30
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/ahub.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_runtime_dependency "rest-client", "~> 1.8"
24
24
  spec.add_runtime_dependency "humanize", "~> 1.1"
25
+ spec.add_runtime_dependency "dotenv", "~> 2.0"
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.10"
27
28
  spec.add_development_dependency "rake", "~> 10.0"
data/lib/ahub/answer.rb CHANGED
@@ -5,23 +5,23 @@ require 'ahub/modules/api_helpers'
5
5
  module Ahub
6
6
  class Answer
7
7
  extend Ahub::APIHelpers
8
- def self.find(id)
9
- end
10
8
 
11
- def self.create(question_id:, body:)
12
- data = {
13
- body: body
14
- }
9
+ def self.create(question_id:, body:, username:, password:)
10
+ data = {body: body}
11
+
12
+ url = "#{Ahub::DOMAIN}/services/v2/question/#{question_id}/answer.json"
15
13
 
16
- url = "http://localhost:8888/services/v2/question/#{question_id}/answer.json"
14
+ auth_headers = headers(username: username, password: password)
17
15
 
18
- JSON.parse RestClient.post(url, data.to_json, headers)
16
+ OpenStruct.new(
17
+ JSON.parse(
18
+ RestClient.post(url, data.to_json, auth_headers),
19
+ symbolize_names: true
20
+ )
21
+ )
19
22
  rescue => e
20
23
  {error: e.message}
21
24
  end
22
25
 
23
- def self.get_all_by_question(question_id:)
24
-
25
- end
26
26
  end
27
27
  end
@@ -4,11 +4,15 @@ module Ahub
4
4
  def headers(username:'answerhub', password:'answerhub')
5
5
  encoded = "Basic #{::Base64.strict_encode64("#{username}:#{password}")}"
6
6
 
7
- headers = {
7
+ {
8
8
  'Authorization' => encoded,
9
9
  'Accept' => "application/json",
10
10
  'Content-type' => "application/json",
11
11
  }
12
12
  end
13
+
14
+ def admin_headers
15
+ headers(username: Ahub::ADMIN_USER, password: Ahub::ADMIN_PASS)
16
+ end
13
17
  end
14
18
  end
@@ -0,0 +1,20 @@
1
+ require 'rest_client'
2
+ require 'pry-byebug'
3
+ require 'ahub/modules/api_helpers'
4
+
5
+ module Ahub
6
+ class Question
7
+ extend Ahub::APIHelpers
8
+
9
+ def self.find(id=nil)
10
+ url = "#{Ahub::DOMAIN}/services/v2/question"
11
+ url +="/#{id}" if id
12
+ url +='.json'
13
+
14
+ OpenStruct.new(JSON.parse(RestClient.get(url, admin_headers), symbolize_names:true))
15
+ rescue => e
16
+ {error: e.message}
17
+ end
18
+
19
+ end
20
+ end
data/lib/ahub/user.rb CHANGED
@@ -7,29 +7,39 @@ require 'ahub/modules/api_helpers'
7
7
  module Ahub
8
8
  class User
9
9
  extend Ahub::APIHelpers
10
- def self.find(id)
11
- url = "http://localhost:8888/services/v2/user/#{id}.json"
12
- JSON.parse(RestClient.get url, headers)
10
+ def self.find(id=nil)
11
+ url = "#{Ahub::DOMAIN}/services/v2/user"
12
+ url += "/#{id}" if id
13
+ url += '.json'
14
+ OpenStruct.new(JSON.parse(RestClient.get(url, admin_headers), symbolize_names:true))
13
15
  rescue => e
14
16
  {error: e.message}
15
17
  end
16
18
 
17
- def self.create_test_user(prefix: 'ahuser', index: 0)
18
- url = "http://localhost:8888/services/v2/user"
19
- number = '%03d' % index
20
- username = "#{prefix}#{number}"
19
+ def self.create(username:, email:, password:)
20
+ url = "#{Ahub::DOMAIN}/services/v2/user"
21
21
  data = {
22
- email: "#{username}@example.com",
22
+ email: email,
23
23
  username: username,
24
- password: 'password',
24
+ password: password,
25
25
  }
26
26
 
27
- JSON.parse RestClient.post(url, data.to_json, headers)
27
+ response = RestClient.post(url, data.to_json, admin_headers)
28
28
  {error: nil, newUserURL: response.headers[:location]}
29
29
  rescue => e
30
30
  {error: e.message}
31
31
  end
32
32
 
33
+ def self.create_test_user(prefix: 'ahuser', index: 0)
34
+ number = '%03d' % index
35
+ username = "#{prefix}#{number}"
36
+ create(
37
+ email: "#{username}@example.com",
38
+ username: username,
39
+ password: Ahub::DEFAULT_PASSWORD,
40
+ )
41
+ end
42
+
33
43
  def self.create_user_csv(prefix: 'ahuser', count: 10)
34
44
  ::CSV.open('./users.csv', 'w') do |csv|
35
45
  (0..count).each do |n|
data/lib/ahub/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ahub
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/ahub.rb CHANGED
@@ -1,8 +1,21 @@
1
1
  require "ahub/version"
2
2
  require "ahub/user"
3
+ require "ahub/question"
3
4
  require "ahub/answer"
5
+ require 'dotenv'
4
6
 
5
7
  module Ahub
8
+ #Load the .env file from the default location...
9
+ Dotenv.load
10
+
11
+ #or a location passed in.
12
+ Dotenv.load ENV['AHUB_ENV_FILE'] if ENV['AHUB_ENV_FILE']
13
+
14
+ DOMAIN = ENV['AHUB_DOMIAN'] || 'http://localhost:8888'
15
+ DEFAULT_PASSWORD = ENV['AHUB_DEFAULT_PASSWORD'] || 'password'
16
+ ADMIN_USER = ENV['AHUB_ADMIN_USER'] || 'answerhub'
17
+ ADMIN_PASS = ENV['AHUB_ADMIN_PASS'] || 'answerhub'
18
+
6
19
  def self.fire
7
20
  "Nailed it!"
8
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abel Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -103,6 +117,7 @@ executables:
103
117
  extensions: []
104
118
  extra_rdoc_files: []
105
119
  files:
120
+ - ".env_example"
106
121
  - ".gitignore"
107
122
  - ".rspec"
108
123
  - ".travis.yml"
@@ -118,6 +133,7 @@ files:
118
133
  - lib/ahub.rb
119
134
  - lib/ahub/answer.rb
120
135
  - lib/ahub/modules/api_helpers.rb
136
+ - lib/ahub/question.rb
121
137
  - lib/ahub/user.rb
122
138
  - lib/ahub/version.rb
123
139
  homepage: https://github.com/abelmartin/ahub