Class: Megam::Reports

Inherits:
RestAdapter show all
Defined in:
lib/megam/core/reports.rb

Instance Attribute Summary

Attributes inherited from RestAdapter

#api_key, #email, #headers, #host, #master_key, #org_id, #password_hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestAdapter

#megam_rest

Constructor Details

#initialize(o) ⇒ Reports

Returns a new instance of Reports.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/megam/core/reports.rb', line 4

def initialize(o)
    @id = nil
    @start_date = nil
    @end_date = nil
    @type_of = nil
    @data = []
    @category = nil
    @group = nil
    @created_at = nil
    @some_msg = {}
    super(o)
end

Class Method Details

.create(params) ⇒ Object



153
154
155
156
# File 'lib/megam/core/reports.rb', line 153

def self.create(params)
    sps = from_hash(params)
    sps.create
end

.from_hash(o) ⇒ Object



138
139
140
141
142
# File 'lib/megam/core/reports.rb', line 138

def self.from_hash(o)
    sps = self.new(o)
    sps.from_hash(o)
    sps
end

.json_create(o) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/megam/core/reports.rb', line 125

def self.json_create(o)
    sps = new({})
    sps.id(o["id"]) if o.has_key?("id")
    sps.start_date(o["start_date"]) if o.has_key?("start_date")
    sps.end_date(o["end_date"]) if o.has_key?("end_date")
    sps.type_of(o["type_of"]) if o.has_key?("type_of")
    sps.data(o["data"]) if o.has_key?("data")
    sps.category(o["category"]) if o.has_key?("category")
    sps.group(o["group"]) if o.has_key?("group")
    sps.created_at(o["created_at"]) if o.has_key?("created_at")
    sps
end

.show(params) ⇒ Object



158
159
160
161
# File 'lib/megam/core/reports.rb', line 158

def self.show(params)
    sps = from_hash(params)
    sps.show
end

Instance Method Details

#category(arg = nil) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/megam/core/reports.rb', line 61

def category(arg=nil)
    if arg !=nil
        @category = arg
    else
        @category
    end
end

#createObject



163
164
165
# File 'lib/megam/core/reports.rb', line 163

def create
    megam_rest.post_reports(to_hash)
end

#created_at(arg = nil) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/megam/core/reports.rb', line 77

def created_at(arg=nil)
    if arg != nil
        @created_date = arg
    else
        @created_date
    end
end

#data(arg = []) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/megam/core/reports.rb', line 53

def data(arg = [])
    if arg != []
        @data = arg
    else
        @data
    end
end

#end_date(arg = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/megam/core/reports.rb', line 37

def end_date(arg=nil)
    if arg != nil
        @end_date = arg
    else
        @end_date
    end
end

#error?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/megam/core/reports.rb', line 93

def error?
    crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#for_jsonObject



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/megam/core/reports.rb', line 111

def for_json
    result = {
        "id" => id,
        "start_date" => start_date,
        "end_date" => end_date,
        "type_of" => type_of,
        "data" => data,
        "category" => category,
        "group" => group,
        "created_at" =>  created_at
    }
    result
end

#from_hash(o) ⇒ Object



144
145
146
147
148
149
150
151
# File 'lib/megam/core/reports.rb', line 144

def from_hash(o)
    @start_date       = o[:start_date] if o.has_key?(:start_date)
    @end_date         = o[:end_date] if o.has_key?(:end_date)
    @type_of          = o[:type_of] if o.has_key?(:type_of)
    @category         = o[:category] if o.has_key?(:category)
    @group            = o[:group] if o.has_key?(:group)
    self
end

#group(arg = nil) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/megam/core/reports.rb', line 69

def group(arg=nil)
    if arg !=nil
        @group = arg
    else
        @group
    end
end

#id(arg = nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/megam/core/reports.rb', line 21

def id(arg=nil)
    if arg != nil
        @id = arg
    else
        @id
    end
end

#reportsObject



17
18
19
# File 'lib/megam/core/reports.rb', line 17

def reports
    self
end

#showObject



167
168
169
# File 'lib/megam/core/reports.rb', line 167

def show
    megam_rest.get_reports(to_hash)
end

#some_msg(arg = nil) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/megam/core/reports.rb', line 85

def some_msg(arg=nil)
    if arg != nil
        @some_msg = arg
    else
        @some_msg
    end
end

#start_date(arg = nil) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/megam/core/reports.rb', line 29

def start_date(arg=nil)
    if arg != nil
        @start_date = arg
    else
        @start_date
    end
end

#to_hashObject



97
98
99
100
101
102
103
104
105
# File 'lib/megam/core/reports.rb', line 97

def to_hash
    index_hash = Hash.new
    index_hash["start_date"] = start_date
    index_hash["end_date"] = end_date
    index_hash["type_of"] = type_of
    index_hash["category"] = category
    index_hash["group"] = group
    index_hash
end

#to_json(*a) ⇒ Object



107
108
109
# File 'lib/megam/core/reports.rb', line 107

def to_json(*a)
    for_json.to_json(*a)
end

#to_sObject



171
172
173
# File 'lib/megam/core/reports.rb', line 171

def to_s
    Megam::Stuff.styled_hash(to_hash)
end

#type_of(arg = nil) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/megam/core/reports.rb', line 45

def type_of(arg=nil)
    if arg != nil
        @type_of = arg
    else
        @type_of
    end
end