Class: GreenButtonData::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/green-button-data/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#application_information_pathObject

Returns the value of attribute application_information_path.



5
6
7
# File 'lib/green-button-data/configuration.rb', line 5

def application_information_path
  @application_information_path
end

#authorization_pathObject

Returns the value of attribute authorization_path.



5
6
7
# File 'lib/green-button-data/configuration.rb', line 5

def authorization_path
  @authorization_path
end

#base_urlObject

Returns the value of attribute base_url.



5
6
7
# File 'lib/green-button-data/configuration.rb', line 5

def base_url
  @base_url
end

#interval_block_pathObject

Returns the value of attribute interval_block_path.



5
6
7
# File 'lib/green-button-data/configuration.rb', line 5

def interval_block_path
  @interval_block_path
end

#local_time_parameters_pathObject

Returns the value of attribute local_time_parameters_path.



5
6
7
# File 'lib/green-button-data/configuration.rb', line 5

def local_time_parameters_path
  @local_time_parameters_path
end

#meter_reading_pathObject

Returns the value of attribute meter_reading_path.



5
6
7
# File 'lib/green-button-data/configuration.rb', line 5

def meter_reading_path
  @meter_reading_path
end

#reading_type_pathObject

Returns the value of attribute reading_type_path.



5
6
7
# File 'lib/green-button-data/configuration.rb', line 5

def reading_type_path
  @reading_type_path
end

#subscription_pathObject

Returns the value of attribute subscription_path.



5
6
7
# File 'lib/green-button-data/configuration.rb', line 5

def subscription_path
  @subscription_path
end

#usage_point_pathObject

Returns the value of attribute usage_point_path.



5
6
7
# File 'lib/green-button-data/configuration.rb', line 5

def usage_point_path
  @usage_point_path
end

#usage_summary_pathObject

Returns the value of attribute usage_summary_path.



5
6
7
# File 'lib/green-button-data/configuration.rb', line 5

def usage_summary_path
  @usage_summary_path
end

Instance Method Details

#application_information_urlObject



16
17
18
# File 'lib/green-button-data/configuration.rb', line 16

def application_information_url
  return URI.join(@base_url, @application_information_path).to_s
end

#application_information_url=(url) ⇒ Object



20
21
22
23
24
# File 'lib/green-button-data/configuration.rb', line 20

def application_information_url=(url)
  uri = URI.parse url
  @base_url = "#{uri.scheme}://#{uri.host}"
  @application_information_path = uri.path
end

#authorization_urlObject



26
27
28
# File 'lib/green-button-data/configuration.rb', line 26

def authorization_url
  return URI.join(@base_url, @authorization_path).to_s
end

#authorization_url=(url) ⇒ Object



30
31
32
33
34
# File 'lib/green-button-data/configuration.rb', line 30

def authorization_url=(url)
  uri = URI.parse url
  @base_url = "#{uri.scheme}://#{uri.host}"
  @authorization_path = uri.path
end

#interval_block_url(kwargs = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/green-button-data/configuration.rb', line 36

def interval_block_url(kwargs = {})
  subscription_id = kwargs[:subscription_id]
  usage_point_id = kwargs[:usage_point_id]
  meter_reading_id = kwargs[:meter_reading_id]
  interval_block_id = kwargs[:interval_block_id]

  uri = if subscription_id && usage_point_id && meter_reading_id
    meter_reading_uri = meter_reading_url(
      subscription_id: subscription_id,
      usage_point_id: usage_point_id,
      meter_reading_id: meter_reading_id
    )

    URI.join meter_reading_uri, @interval_block_path
  else
    URI.join @base_url, @interval_block_path
  end

  uri = URI.join uri, "#{interval_block_id}/" if interval_block_id

  return uri.to_s
end

#local_time_parameters_urlObject



59
60
61
# File 'lib/green-button-data/configuration.rb', line 59

def local_time_parameters_url
  return URI.join @base_url, @local_time_parameters_path
end

#meter_reading_url(kwargs = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/green-button-data/configuration.rb', line 63

def meter_reading_url(kwargs = {})
  subscription_id = kwargs[:subscription_id]
  usage_point_id = kwargs[:usage_point_id]
  meter_reading_id = kwargs[:meter_reading_id]

  uri = if subscription_id && usage_point_id
    usage_point_uri = usage_point_url(
      subscription_id: subscription_id,
      usage_point_id: usage_point_id
    )

    URI.join usage_point_uri, @meter_reading_path
  else
    URI.join @base_url, @meter_reading_path
  end

  uri = URI.join uri, "#{meter_reading_id}/" if meter_reading_id

  return uri.to_s
end

#reading_type_url(id = nil) ⇒ Object



84
85
86
87
88
89
# File 'lib/green-button-data/configuration.rb', line 84

def reading_type_url(id = nil)
  uri = URI.join @base_url, @reading_type_path
  uri = URI.join uri, "#{id}/" if id

  return uri.to_s
end

#subscription_url(id) ⇒ Object



91
92
93
94
95
# File 'lib/green-button-data/configuration.rb', line 91

def subscription_url(id)
  uri = URI.join @base_url, @subscription_path
  uri = URI.join uri, "#{id}/" if id
  return uri.to_s
end

#usage_point_url(kwargs = {}) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/green-button-data/configuration.rb', line 97

def usage_point_url(kwargs = {})
  subscription_id = kwargs[:subscription_id]
  usage_point_id = kwargs[:usage_point_id]

  uri = if subscription_id
    subscription_uri = subscription_url subscription_id

    URI.join subscription_uri, @usage_point_path
  else
    URI.join @base_url, @usage_point_path
  end

  uri = URI.join uri, "#{usage_point_id}/" if usage_point_id

  return uri.to_s
end

#usage_summary_url(kwargs = {}) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/green-button-data/configuration.rb', line 114

def usage_summary_url(kwargs = {})
  subscription_id = kwargs[:subscription_id]
  usage_point_id = kwargs[:usage_point_id]

  if subscription_id && usage_point_id
    usage_point_uri = usage_point_url subscription_id: subscription_id,
                                      usage_point_id: usage_point_id

    return URI.join(usage_point_uri, @usage_summary_path).to_s
  elsif subscription_id
    raise ArgumentError.new "Missing required argument: usage_point_id"
  elsif usage_point_id
    raise ArgumentError.new "Missing required argument: subscription_id"
  else
    raise ArgumentError.new "Missing required arguments: subscription_id," +
                            " usage_point_id"
  end
end