genability 0.1.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.
Files changed (52) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/.yardopts +10 -0
  4. data/Gemfile +18 -0
  5. data/HISTORY.md +7 -0
  6. data/LICENSE.md +20 -0
  7. data/README.md +79 -0
  8. data/Rakefile +42 -0
  9. data/VERSION +1 -0
  10. data/genability.gemspec +123 -0
  11. data/lib/faraday/request/url_encoding_fix.rb +19 -0
  12. data/lib/faraday/response/raise_http_4xx.rb +44 -0
  13. data/lib/faraday/response/raise_http_5xx.rb +25 -0
  14. data/lib/genability.rb +29 -0
  15. data/lib/genability/api.rb +26 -0
  16. data/lib/genability/client.rb +24 -0
  17. data/lib/genability/client/helpers.rb +57 -0
  18. data/lib/genability/client/load_serving_entity.rb +77 -0
  19. data/lib/genability/client/price.rb +53 -0
  20. data/lib/genability/client/season.rb +27 -0
  21. data/lib/genability/client/tariff.rb +80 -0
  22. data/lib/genability/client/territory.rb +80 -0
  23. data/lib/genability/client/time_of_use.rb +66 -0
  24. data/lib/genability/client/zip_code.rb +28 -0
  25. data/lib/genability/configuration.rb +82 -0
  26. data/lib/genability/connection.rb +41 -0
  27. data/lib/genability/error.rb +21 -0
  28. data/lib/genability/request.rb +46 -0
  29. data/lib/mashie_extensions.rb +32 -0
  30. data/spec/cassettes/load_serving_entities.yml +163 -0
  31. data/spec/cassettes/load_serving_entity.yml +28 -0
  32. data/spec/cassettes/prices.yml +55 -0
  33. data/spec/cassettes/seasons.yml +28 -0
  34. data/spec/cassettes/tariff.yml +28 -0
  35. data/spec/cassettes/tariffs.yml +82 -0
  36. data/spec/cassettes/territories.yml +28 -0
  37. data/spec/cassettes/territory.yml +28 -0
  38. data/spec/cassettes/time_of_use.yml +30 -0
  39. data/spec/cassettes/time_of_uses.yml +28 -0
  40. data/spec/cassettes/zipcode.yml +28 -0
  41. data/spec/client/load_serving_entity_spec.rb +72 -0
  42. data/spec/client/price_spec.rb +41 -0
  43. data/spec/client/season_spec.rb +30 -0
  44. data/spec/client/tariff_spec.rb +52 -0
  45. data/spec/client/territory_spec.rb +40 -0
  46. data/spec/client/time_of_use_spec.rb +42 -0
  47. data/spec/client/zip_code_spec.rb +30 -0
  48. data/spec/configuration.yml.sample +3 -0
  49. data/spec/faraday/response_spec.rb +31 -0
  50. data/spec/genability_spec.rb +138 -0
  51. data/spec/spec_helper.rb +78 -0
  52. metadata +236 -0
@@ -0,0 +1,30 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Genability::Client do
4
+
5
+ Genability::Configuration::VALID_FORMATS.each do |format|
6
+
7
+ context ".new(:format => '#{format}')" do
8
+
9
+ before(:all) do
10
+ @options = {:format => format}.merge(configuration_defaults)
11
+ @client = Genability::Client.new(@options)
12
+ end
13
+
14
+ context ".seasons" do
15
+
16
+ use_vcr_cassette "seasons"
17
+
18
+ it "should return a list of season groups" do
19
+ seasons = @client.seasons(734)
20
+ seasons.should be_an Array
21
+ seasons.first.seasons.count.should == 2
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
30
+
@@ -0,0 +1,52 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Genability::Client do
4
+
5
+ Genability::Configuration::VALID_FORMATS.each do |format|
6
+
7
+ context ".new(:format => '#{format}')" do
8
+
9
+ before(:all) do
10
+ @options = {:format => format}.merge(configuration_defaults)
11
+ @client = Genability::Client.new(@options)
12
+ end
13
+
14
+ context ".tariffs" do
15
+
16
+ use_vcr_cassette "tariffs"
17
+
18
+ it "should return an array of tariffs" do
19
+ tariffs = @client.tariffs
20
+ tariffs.should be_an Array
21
+ tariffs.first.tariff_id.should == 79
22
+ end
23
+
24
+ it "should accept a string for customerClasses and tariffTypes parameters" do
25
+ @client.tariffs(:customer_classes => 'residential').each do |tariff|
26
+ tariff.customer_class.should =~ /RESIDENTIAL/
27
+ end
28
+ end
29
+
30
+ it "should accept an array for customerClasses and tariffTypes parameters" do
31
+ @client.tariffs(:tariff_types => ['default', 'alternative']).each do |tariff|
32
+ tariff.tariff_type.should =~ /(DEFAULT)|(ALTERNATIVE)/
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ context ".tariff" do
39
+
40
+ use_vcr_cassette "tariff"
41
+
42
+ it "should return a tariff" do
43
+ @client.tariff(512).tariff_id.should == 512
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+ end
52
+
@@ -0,0 +1,40 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Genability::Client do
4
+
5
+ Genability::Configuration::VALID_FORMATS.each do |format|
6
+
7
+ context ".new(:format => '#{format}')" do
8
+
9
+ before(:all) do
10
+ @options = {:format => format}.merge(configuration_defaults)
11
+ @client = Genability::Client.new(@options)
12
+ end
13
+
14
+ context ".territories" do
15
+
16
+ use_vcr_cassette "territories"
17
+
18
+ it "should return an array of territories" do
19
+ territories = @client.territories(:lse_id => 734)
20
+ territories.should be_an Array
21
+ territories.first.territory_id.should == 807
22
+ end
23
+
24
+ end
25
+
26
+ context ".territory" do
27
+
28
+ use_vcr_cassette "territory"
29
+
30
+ it "should return a territory" do
31
+ @client.territory(3539).lse_id.should == 734
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
40
+
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Genability::Client do
4
+
5
+ Genability::Configuration::VALID_FORMATS.each do |format|
6
+
7
+ context ".new(:format => '#{format}')" do
8
+
9
+ before(:all) do
10
+ @options = {:format => format}.merge(configuration_defaults)
11
+ @client = Genability::Client.new(@options)
12
+ end
13
+
14
+ context ".time_of_uses" do
15
+
16
+ use_vcr_cassette "time_of_uses"
17
+
18
+ it "should return an the time of uses for a given LSE and touGroupId" do
19
+ time_of_uses = @client.time_of_uses(2756, 1)
20
+ time_of_uses.should be_an Hashie::Mash
21
+ time_of_uses.time_of_uses.count.should == 2
22
+ end
23
+
24
+ end
25
+
26
+ context ".time_of_use" do
27
+
28
+ use_vcr_cassette "time_of_use"
29
+
30
+ it "should return a territory" do
31
+ intervals = @client.time_of_use_intervals(2756, 1)
32
+ intervals.should be_an Array
33
+ intervals.first.tou_group_id.should == 1
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
42
+
@@ -0,0 +1,30 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Genability::Client do
4
+
5
+ Genability::Configuration::VALID_FORMATS.each do |format|
6
+
7
+ context ".new(:format => '#{format}')" do
8
+
9
+ before(:all) do
10
+ @options = {:format => format}.merge(configuration_defaults)
11
+ @client = Genability::Client.new(@options)
12
+ end
13
+
14
+ context ".zipcode" do
15
+
16
+ use_vcr_cassette "zipcode"
17
+
18
+ it "should return details for a given zipcode" do
19
+ zipcode = @client.zipcode('48322')
20
+ zipcode.should be_an Hashie::Mash
21
+ zipcode.city.should == "WEST BLOOMFIELD"
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
30
+
@@ -0,0 +1,3 @@
1
+ application_id: ValidAppID
2
+ application_key: ValidAppKey
3
+
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Faraday::Response do
4
+
5
+ before do
6
+ @client = Genability::Client.new({:application_id => 'ValidAppID', :application_key => 'ValidAppKey'})
7
+ end
8
+
9
+ {
10
+ 400 => Genability::BadRequest,
11
+ 403 => Genability::Forbidden,
12
+ 404 => Genability::NotFound,
13
+ 500 => Genability::ServerError,
14
+ 503 => Genability::ServiceUnavailable
15
+ }.each do |status, exception|
16
+ context "when HTTP status is #{status}" do
17
+
18
+ before do
19
+ stub_get('lses.json?appId=ValidAppID&appKey=ValidAppKey').
20
+ to_return(:status => status)
21
+ end
22
+
23
+ it "should raise #{exception.name} error" do
24
+ lambda do
25
+ @client.load_serving_entities()
26
+ end.should raise_error(exception)
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,138 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Genability" do
4
+
5
+ context "default values" do
6
+ it { Genability::Configuration::DEFAULT_ADAPTER.should == :net_http }
7
+ it { Genability::Configuration::DEFAULT_APPLICATION_ID.should be_nil }
8
+ it { Genability::Configuration::DEFAULT_APPLICATION_KEY.should be_nil }
9
+ it { Genability::Configuration::DEFAULT_ENDPOINT.should == 'http://api.genability.com/rest/public/' }
10
+ it { Genability::Configuration::DEFAULT_FORMAT.should == :json }
11
+ it { Genability::Configuration::DEFAULT_USER_AGENT.should == 'Genability API Ruby Gem' }
12
+ it { Genability::Configuration::DEFAULT_PROXY.should be_nil }
13
+ end
14
+
15
+ context ".client" do
16
+ it "should be a Genability::Client" do
17
+ Genability.client.should be_a Genability::Client
18
+ end
19
+ end
20
+
21
+ context ".adapter" do
22
+ it "should return the default adapter" do
23
+ Genability.adapter.should == Genability::Configuration::DEFAULT_ADAPTER
24
+ end
25
+ end
26
+
27
+ context ".adapter=" do
28
+ it "should set the adapter" do
29
+ Genability.adapter = :typhoeus
30
+ Genability.adapter.should == :typhoeus
31
+ end
32
+ end
33
+
34
+ context ".application_id" do
35
+ it "should return the default application id" do
36
+ Genability.application_id.should == Genability::Configuration::DEFAULT_APPLICATION_ID
37
+ end
38
+ end
39
+
40
+ context ".application_id=" do
41
+ it "should set the application id" do
42
+ Genability.application_id = '1234'
43
+ Genability.application_id.should == '1234'
44
+ end
45
+ end
46
+
47
+ context ".application_key" do
48
+ it "should return the default application key" do
49
+ Genability.application_key.should == Genability::Configuration::DEFAULT_APPLICATION_KEY
50
+ end
51
+ end
52
+
53
+ context ".application_key=" do
54
+ it "should set the application key" do
55
+ Genability.application_key = '5678'
56
+ Genability.application_key.should == '5678'
57
+ end
58
+ end
59
+
60
+ context ".endpoint" do
61
+ it "should return the default endpoint" do
62
+ Genability.endpoint.should == Genability::Configuration::DEFAULT_ENDPOINT
63
+ end
64
+ end
65
+
66
+ context ".endpoint=" do
67
+ it "should set the endpoint" do
68
+ Genability.endpoint = 'http://tumblr.com'
69
+ Genability.endpoint.should == 'http://tumblr.com'
70
+ end
71
+ end
72
+
73
+ context ".format" do
74
+ it "should return the default format" do
75
+ Genability.format.should == Genability::Configuration::DEFAULT_FORMAT
76
+ end
77
+ end
78
+
79
+ context ".format=" do
80
+ it "should set the format" do
81
+ Genability.format = 'xml'
82
+ Genability.format.should == 'xml'
83
+ end
84
+ end
85
+
86
+ context ".user_agent" do
87
+ it "should return the default user agent" do
88
+ Genability.user_agent.should == Genability::Configuration::DEFAULT_USER_AGENT
89
+ end
90
+ end
91
+
92
+ context ".user_agent=" do
93
+ it "should set the user_agent" do
94
+ Genability.user_agent = 'Custom User Agent'
95
+ Genability.user_agent.should == 'Custom User Agent'
96
+ end
97
+ end
98
+
99
+ context ".proxy" do
100
+ it "should return the default proxy" do
101
+ Genability.proxy.should == Genability::Configuration::DEFAULT_PROXY
102
+ end
103
+ end
104
+
105
+ context ".proxy=" do
106
+ it "should set the proxy" do
107
+ Genability.proxy = 'http://127.0.0.1'
108
+ Genability.proxy.should == 'http://127.0.0.1'
109
+ end
110
+ end
111
+
112
+ context ".options" do
113
+ it "should retreive a hash of options and their values" do
114
+ Genability.options.keys.should == Genability::Configuration::VALID_OPTIONS_KEYS
115
+ end
116
+ end
117
+
118
+ context ".reset" do
119
+ it "should restore the options to their default values" do
120
+ Genability.adapter = :typhoeus
121
+ Genability.reset
122
+ Genability.adapter.should == Genability::Configuration::DEFAULT_ADAPTER
123
+ end
124
+ end
125
+
126
+ context ".configure" do
127
+ Genability::Configuration::VALID_OPTIONS_KEYS.each do |key|
128
+ it "should set the #{key}" do
129
+ Genability.configure do |config|
130
+ config.send("#{key}=", key)
131
+ Genability.send(key).should == key
132
+ end
133
+ end
134
+ end
135
+ end
136
+
137
+ end
138
+
@@ -0,0 +1,78 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'webmock/rspec'
5
+ require 'genability'
6
+ require 'vcr'
7
+
8
+ CONFIGURATION_DEFAULTS = begin
9
+ YAML::load_file("#{File.dirname(__FILE__)}/configuration.yml").inject({}) do |options, (key, value)|
10
+ options[(key.to_sym rescue key) || key] = value
11
+ options
12
+ end
13
+ rescue
14
+ {:application_id => 'ValidAppID', :application_key => 'ValidAppKey'}
15
+ end
16
+
17
+ # Requires supporting files with custom matchers and macros, etc,
18
+ # in ./support/ and its subdirectories.
19
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
20
+
21
+ RSpec.configure do |config|
22
+ config.include WebMock::API
23
+ config.extend VCR::RSpec::Macros
24
+ end
25
+
26
+ VCR.config do |c|
27
+ c.ignore_localhost = true
28
+ c.cassette_library_dir = 'spec/cassettes'
29
+ c.stub_with :webmock #:typhoeus, :faraday, :fakeweb, or :webmock
30
+ c.default_cassette_options = { :record => :new_episodes }
31
+ c.filter_sensitive_data('ValidAppID') { CONFIGURATION_DEFAULTS[:application_id] }
32
+ c.filter_sensitive_data('ValidAppKey') { CONFIGURATION_DEFAULTS[:application_key] }
33
+ end
34
+
35
+ def configuration_defaults
36
+ CONFIGURATION_DEFAULTS
37
+ end
38
+
39
+ def a_delete(path)
40
+ a_request(:delete, Genability.endpoint + path)
41
+ end
42
+
43
+ def a_get(path)
44
+ a_request(:get, Genability.endpoint + path)
45
+ end
46
+
47
+ def a_post(path)
48
+ a_request(:post, Genability.endpoint + path)
49
+ end
50
+
51
+ def a_put(path)
52
+ a_request(:put, Genability.endpoint + path)
53
+ end
54
+
55
+ def stub_delete(path)
56
+ stub_request(:delete, Genability.endpoint + path)
57
+ end
58
+
59
+ def stub_get(path)
60
+ stub_request(:get, Genability.endpoint + path)
61
+ end
62
+
63
+ def stub_post(path)
64
+ stub_request(:post, Genability.endpoint + path)
65
+ end
66
+
67
+ def stub_put(path)
68
+ stub_request(:put, Genability.endpoint + path)
69
+ end
70
+
71
+ def fixture_path
72
+ File.expand_path("../fixtures", __FILE__)
73
+ end
74
+
75
+ def fixture(file)
76
+ File.new(fixture_path + '/' + file)
77
+ end
78
+