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

#bulk_pathObject

Returns the value of attribute bulk_path.



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

def bulk_path
  @bulk_path
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

#retail_customer_pathObject

Returns the value of attribute retail_customer_path.



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

def retail_customer_path
  @retail_customer_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_url(id = nil) ⇒ Object



18
19
20
# File 'lib/green-button-data/configuration.rb', line 18

def application_information_url(id = nil)
  return build_url @application_information_path, id
end

#application_information_url=(url) ⇒ Object



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

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

#authorization_url(id = nil) ⇒ Object



28
29
30
# File 'lib/green-button-data/configuration.rb', line 28

def authorization_url(id = nil)
  return build_url @authorization_path, id
end

#authorization_url=(url) ⇒ Object



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

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

#bulk_url(kwargs = {}) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/green-button-data/configuration.rb', line 141

def bulk_url(kwargs = {})
  subscription_id = kwargs[:subscription_id]
  bulk_file_id = kwargs[:bulk_file_id]

  if subscription_id && bulk_file_id
    bulk_url = build_url(@bulk_path)
    return "#{bulk_url}/#{subscription_id}/#{bulk_file_id}"
  else
    raise ArgumentError.new "Missing required arguments: subscription_id or bulk_file_id"
  end
end

#interval_block_url(kwargs = {}) ⇒ Object



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

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_url(id = nil) ⇒ Object



61
62
63
# File 'lib/green-button-data/configuration.rb', line 61

def local_time_parameters_url(id = nil)
  return build_url @local_time_parameters_path, id
end

#meter_reading_url(kwargs = {}) ⇒ Object



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

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



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

def reading_type_url(id = nil)
  return build_url @reading_type_path, id
end

#retail_customer_url(kwargs = {}) ⇒ Object



130
131
132
133
134
135
136
137
138
139
# File 'lib/green-button-data/configuration.rb', line 130

def retail_customer_url(kwargs = {})
  retail_customer_id = kwargs[:subscription_id]

  if retail_customer_id
    retail_customer_url = build_url(@retail_customer_path)
    return "#{retail_customer_url}/#{retail_customer_id}"
  else
    raise ArgumentError.new "Missing required arguments: subscription_id"
  end
end

#subscription_url(id) ⇒ Object



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

def subscription_url(id)
  return build_url @subscription_path, id
end

#usage_point_url(kwargs = {}) ⇒ Object



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

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



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

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