hdcore 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - 1.8.7
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Hdcore
2
2
 
3
+ ![image](https://travis-ci.org/hostdime/hdcore-rb.png)
4
+
3
5
  A basic wrapper for HostDime.com's customer portal 'Core' API.
4
6
 
5
7
  ## Installation
@@ -18,6 +20,18 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
23
+ Before use, the library must be configured with your client key:
24
+
25
+ Hdcore.configure(public_key: 'foobar', private_key: 'fazbaz')
26
+ # or perhaps
27
+ Hdcore.configure_with(path_to_some_yml_config_file)
28
+
29
+ API calls are then made statically, and return HTTParty response objects.
30
+
31
+ # An example of an action with parameters
32
+ Hdcore::Request.call('server.get', {:cuid => 'S37'})
33
+
34
+ For details on API specification, visit
21
35
  https://api.hostdime.com/
22
36
 
23
37
  ## Contributing
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -5,8 +5,18 @@ module Hdcore
5
5
 
6
6
  class << self
7
7
 
8
- # Initializes the request: throws exception if there are configs missing (requires public and private keys)
9
8
  # @param [String] action The full API action
9
+ # @param [Hash] params The given action parameters
10
+ # @return [HTTParty::Response]
11
+ def call(action, params = {})
12
+ init()
13
+ self.get("/call/api_action/#{action}/format/json/", query_string(action, params))
14
+ end
15
+
16
+ private
17
+
18
+ # @private
19
+ # Initializes the request: throws exception if there are configs missing (requires public and private keys)
10
20
  def init
11
21
  # Make sure required config values are set
12
22
  if Hdcore.missing_config_values?
@@ -20,32 +30,30 @@ module Hdcore
20
30
  base_uri Hdcore.config[:api_endpoint]
21
31
  end
22
32
 
33
+ # @private
23
34
  # @return [String] public key established in configuration
24
35
  def public_key
25
36
  Hdcore.config[:public_key]
26
37
  end
27
38
 
39
+ # @private
28
40
  # @return [String] private key established in configuration
29
41
  def private_key
30
42
  Hdcore.config[:private_key]
31
43
  end
32
44
 
45
+ # @private
33
46
  # @param [String] action The full API action
34
- # @param [Hash] params The given action parameters
35
- # @return [HTTParty::Response]
36
- def send(action, params = {})
37
- init()
38
- self.get("/call/api_action/#{action}/format/json/", query_string(action, params))
39
- end
40
-
41
47
  # @param [Hash] params The given action parameters
42
48
  # @return [Hash] Full set of parameters, including generated api parameters
43
49
  def query_string(action, params = {})
44
50
  params.merge generate_api_params(action, params)
45
51
  end
46
52
 
53
+ # @private
54
+ # @param [String] action The full API action
47
55
  # @param [Hash] action_params The given action parameters
48
- # @return [Hash] required api parameters: [api_key, api_unique, api_timestamp, api_hash]
56
+ # @return [Hash] required api parameters: {:api_key, :api_unique, :api_timestamp, :api_hash}
49
57
  def generate_api_params(action, params = {})
50
58
  {
51
59
  api_key: public_key,
@@ -59,11 +67,13 @@ module Hdcore
59
67
  }
60
68
  end
61
69
 
70
+ # @private
62
71
  # @return [String] SHA256 hash of all the arguments "joined:with:colons"
63
72
  def generate_hash(*args)
64
73
  (Digest::SHA2.new << args.join(':')).to_s
65
74
  end
66
75
 
76
+ # @private
67
77
  # @return [String] Version 4 UUID
68
78
  # More: http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29
69
79
  def generate_uuid
@@ -1,3 +1,3 @@
1
1
  module Hdcore
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -7,8 +7,8 @@ describe Hdcore do
7
7
  Hdcore.config.keys.should == [:api_endpoint, :public_key, :private_key]
8
8
  end
9
9
 
10
- it 'returns default [:api_endpoint] => "core.hostdime.com/api/v1"' do
11
- Hdcore.config[:api_endpoint].should == 'core.hostdime.com/api/v1'
10
+ it 'returns default [:api_endpoint] => "https://core.hostdime.com/api/v1"' do
11
+ Hdcore.config[:api_endpoint].should == 'https://core.hostdime.com/api/v1'
12
12
  end
13
13
 
14
14
  it 'returns default [:public_key] => nil' do
@@ -2,13 +2,13 @@ require_relative '../../../lib/hdcore'
2
2
 
3
3
  describe Hdcore::Request do
4
4
 
5
- describe '.send' do
5
+ describe '.call' do
6
6
  it 'initializes and sends GET request to API endpoint' do
7
7
  test_action = 'some.action'
8
8
  Hdcore::Request.stub(:query_string).and_return(params = {some: 'params'})
9
9
  Hdcore::Request.should_receive(:init)
10
10
  Hdcore::Request.should_receive(:get).with("/call/api_action/#{test_action}/format/json/", params)
11
- Hdcore::Request.send(test_action, {})
11
+ Hdcore::Request.call(test_action, {})
12
12
  end
13
13
  end
14
14
 
@@ -16,7 +16,7 @@ describe Hdcore::Request do
16
16
  describe '.query_string' do
17
17
  it 'returns parameters merged with generated api parameters' do
18
18
  Hdcore::Request.stub(:generate_api_params).and_return(api_params = {some: 'api_params'})
19
- actual = Hdcore::Request.query_string('some.action', params = {some_other: 'params'})
19
+ actual = Hdcore::Request.send(:query_string, 'some.action', params = {some_other: 'params'})
20
20
  actual.should == params.merge(api_params)
21
21
  end
22
22
  end
@@ -24,31 +24,31 @@ describe Hdcore::Request do
24
24
 
25
25
  describe '.generate_api_params' do
26
26
  it 'returns hash with four valid param keys' do
27
- actual = Hdcore::Request.generate_api_params("", {})
27
+ actual = Hdcore::Request.send(:generate_api_params, "", {})
28
28
  actual.keys.should == [:api_key, :api_unique, :api_timestamp, :api_hash]
29
29
  end
30
30
 
31
31
  it 'returns [:api_key] => public key' do
32
32
  Hdcore::Request.stub(:public_key).and_return(key = 'some_public_key')
33
- actual = Hdcore::Request.generate_api_params("", {})
33
+ actual = Hdcore::Request.send(:generate_api_params, "", {})
34
34
  actual[:api_key].should == key
35
35
  end
36
36
 
37
37
  it 'returns [:api_unique] => generated uuid' do
38
38
  Hdcore::Request.stub(:generate_uuid).and_return(uuid = 'some_uuid')
39
- actual = Hdcore::Request.generate_api_params("", {})
39
+ actual = Hdcore::Request.send(:generate_api_params, "", {})
40
40
  actual[:api_unique].should == uuid
41
41
  end
42
42
 
43
43
  it 'returns [:api_timestamp] => time of execution' do
44
44
  timestamp = Time.now.to_i
45
- actual = Hdcore::Request.generate_api_params("", {})
45
+ actual = Hdcore::Request.send(:generate_api_params, "", {})
46
46
  actual[:api_timestamp].should == timestamp
47
47
  end
48
48
 
49
49
  it 'returns [:api_hash] => generated hash' do
50
50
  Hdcore::Request.stub(:generate_hash).and_return(hash = 'some_hash')
51
- actual = Hdcore::Request.generate_api_params("", {})
51
+ actual = Hdcore::Request.send(:generate_api_params, "", {})
52
52
  actual[:api_hash].should == hash
53
53
  end
54
54
 
@@ -64,7 +64,7 @@ describe Hdcore::Request do
64
64
  (params = {some: 'optional_params'}).to_json
65
65
  )
66
66
 
67
- Hdcore::Request.generate_api_params(action, params)
67
+ Hdcore::Request.send(:generate_api_params, action, params)
68
68
  end
69
69
  end
70
70
 
@@ -73,14 +73,14 @@ describe Hdcore::Request do
73
73
  it 'uses the SHA256 algorithm, and joins parameters with colons' do
74
74
  args = %w[one two three 4 five seven 8]
75
75
  hash = (Digest::SHA2.new << args.join(':')).to_s
76
- Hdcore::Request.generate_hash(*args).should == hash
76
+ Hdcore::Request.send(:generate_hash, args).should == hash
77
77
  end
78
78
  end
79
79
 
80
80
  describe '.generate_uuid' do
81
81
  it 'uses Version 4 UUID' do
82
82
  SecureRandom.should_receive(:uuid).and_return(uuid = 'some_uuid')
83
- Hdcore::Request.generate_uuid.should == uuid
83
+ Hdcore::Request.send(:generate_uuid).should == uuid
84
84
  end
85
85
  end
86
86
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hdcore
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ethan Pemble
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-05-08 00:00:00 Z
18
+ date: 2013-05-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler
@@ -87,6 +87,7 @@ extra_rdoc_files: []
87
87
 
88
88
  files:
89
89
  - .gitignore
90
+ - .travis.yml
90
91
  - Gemfile
91
92
  - LICENSE.txt
92
93
  - README.md