Module: Lifeapi
- Defined in:
- lib/lifeapi.rb,
lib/lifeapi/version.rb
Defined Under Namespace
Classes: Activity, Day, Query, Query_activity, Range
Constant Summary collapse
- VERSION =
"1.3.0"
Class Method Summary collapse
-
.all_time(condense) ⇒ Object
the same thing as self.range() except the server collects every recorded day.
-
.query(month, day, hour, minute) ⇒ Object
returns the activity being performed at a certain time.
-
.range(month1, day1, month2, day2, condense) ⇒ Object
returns a range of days if the condense param is true it will return a condensed object representing the range of days otherwise it will retun an array of the days.
-
.single_day(month, day) ⇒ Object
returns a single day.
Class Method Details
.all_time(condense) ⇒ Object
the same thing as self.range() except the server collects every recorded day.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/lifeapi.rb', line 152 def self.all_time(condense) @condense = condense json_data = HTTParty.get("https://jack-lifeapi.herokuapp.com/v1/days/all_time?condense=#{@condense}") #if the params are bad if json_data.code == 400 raise Errors::BadParamsError end data = JSON.parse(json_data.to_json) if @condense == true day = Range.new(data["start_date"], data["end_date"], data["activities"]) return day else @day_array = [] data.each do |d| @day = Day.new(d["record_date"], d["activities"]) @day_array += [@day] end return @day_array end end |
.query(month, day, hour, minute) ⇒ Object
returns the activity being performed at a certain time.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/lifeapi.rb', line 177 def self.query(month, day, hour, minute) @year = 2016 # year is hardcoded right now because i dont track anything outside of 2016 @month = month @day = day @hour = hour @minute = minute json_data = HTTParty.get("https://jack-lifeapi.herokuapp.com/v1/days/query?year=#{@year}&month=#{@month}&day=#{@day}&hour=#{@hour}&minute=#{@minute}") #if the params are bad if json_data.code == 400 raise Errors::BadParamsError end data = JSON.parse(json_data.to_json) #day = Range.new(data["start_date"], data["end_date"], data["activities"]) query = Query.new(data["query_time"], data["record_date"], data["activity"]) return query end |
.range(month1, day1, month2, day2, condense) ⇒ Object
returns a range of days if the condense param is true it will return a condensed object representing the range of days otherwise it will retun an array of the days
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/lifeapi.rb', line 119 def self.range(month1, day1, month2, day2, condense) @year1 = 2016 @month1 = month1 @day1 = day1 @year2 = 2016 @month2 = month2 @day2 = day2 @condense = condense json_data = HTTParty.get("https://jack-lifeapi.herokuapp.com/v1/days/range?year1=#{@year1}&month1=#{@month1}&day1=#{@day1}&year2=#{@year2}&month2=#{@month2}&day2=#{@day2}&condense=#{@condense}") #if the params are bad if json_data.code == 400 raise Errors::BadParamsError end data = JSON.parse(json_data.to_json) #if the data is condensed it needs to be handled differently if @condense == true day = Range.new(data["start_date"], data["end_date"], data["activities"]) return day else @day_array = [] data.each do |d| @day = Day.new(d["record_date"], d["activities"]) @day_array += [@day] end return @day_array end end |
.single_day(month, day) ⇒ Object
returns a single day
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/lifeapi.rb', line 99 def self.single_day(month, day) @year = 2016 @month = month @day = day json_data = HTTParty.get("https://jack-lifeapi.herokuapp.com/v1/days/single?year=#{@year}&month=#{@month}&day=#{day}") #if the params are bad if json_data.code == 400 raise Errors::BadParamsError end data = JSON.parse(json_data.to_json) day = Day.new(data["record_date"],data["activities"]) return day end |