Class: PortaText::Command::Api::Summary

Inherits:
Base
  • Object
show all
Defined in:
lib/portatext/command/api/summary.rb

Overview

The summary endpoint. github.com/PortaText/docs/wiki/REST-API#api_summary

Author

Marcelo Gornstein ([email protected])

Copyright

Copyright © 2015 PortaText

License

Apache-2.0

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#accept_content_type, #body, #content_type, #delete, #get, #initialize, #patch, #post, #put, #set

Constructor Details

This class inherits a constructor from PortaText::Command::Base

Instance Method Details

#by_dayObject



23
24
25
# File 'lib/portatext/command/api/summary.rb', line 23

def by_day
  set :granularity, 'date'
end

#by_monthObject



27
28
29
# File 'lib/portatext/command/api/summary.rb', line 27

def by_month
  set :granularity, 'month'
end

#by_weekObject



31
32
33
# File 'lib/portatext/command/api/summary.rb', line 31

def by_week
  set :granularity, 'week'
end

#endpoint(_method) ⇒ Object

rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/portatext/command/api/summary.rb', line 37

def endpoint(_method)
  qs = {}
  unless @args[:date_from].nil?
    qs[:date_from] = @args[:date_from]
    @args.delete :date_from
  end
  unless @args[:date_to].nil?
    qs[:date_to] = @args[:date_to]
    @args.delete :date_to
  end
  unless @args[:granularity].nil?
    qs[:granularity] = @args[:granularity]
    @args.delete :granularity
  end
  unless qs.empty?
    qs = URI.encode_www_form qs
    return "summary?#{qs}"
  end

  'summary'
end

#from(date) ⇒ Object



15
16
17
# File 'lib/portatext/command/api/summary.rb', line 15

def from(date)
  set :date_from, date
end

#save_to(file) ⇒ Object



19
20
21
# File 'lib/portatext/command/api/summary.rb', line 19

def save_to(file)
  set :accept_file, file
end

#to(date) ⇒ Object



11
12
13
# File 'lib/portatext/command/api/summary.rb', line 11

def to(date)
  set :date_to, date
end