Class: Urtak::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/urtak.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_options = {}) ⇒ Api

Returns a new instance of Api.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/urtak.rb', line 17

def initialize(user_options = {})
  @options = {
    :api_key          => nil,
    :publication_key  => nil,
    :email            => nil,
    :user_id          => nil,
    :api_base         => "https://urtak.com/api",
    :api_format       => "JSON",
    :client_name      => "Urtak API Wrapper for Ruby, v#{Urtak::VERSION}"
  }.merge(user_options.select{|k,v|!v.nil?})
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



15
16
17
# File 'lib/urtak.rb', line 15

def logger
  @logger
end

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/urtak.rb', line 15

def options
  @options
end

Instance Method Details

#approve_urtak_question(property, value, id) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/urtak.rb', line 132

def approve_urtak_question(property, value, id)
  if property == :id
    path = "urtaks/#{value}/questions/#{id}/approve"
  elsif property == :post_id
    path = "urtaks/post/#{value}/questions/#{id}/approve"
  elsif property == :permalink
    path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions/#{id}/approve"
  end

  create_response(fire(:put, path))
end

#create_account(attributes) ⇒ Object



43
44
45
# File 'lib/urtak.rb', line 43

def (attributes)
  create_response(fire(:post, "accounts", {:account => attributes}))
end

#create_publication(attributes) ⇒ Object



52
53
54
# File 'lib/urtak.rb', line 52

def create_publication(attributes)
  create_response(fire(:post, "publications", {:publication => attributes}))
end

#create_urtak(urtak_attributes, questions = []) ⇒ Object



77
78
79
# File 'lib/urtak.rb', line 77

def create_urtak(urtak_attributes, questions=[])
  create_response(fire(:post, 'urtaks', {:urtak => urtak_attributes.merge(:questions => questions)}))
end

#create_urtak_question(property, value, question) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/urtak.rb', line 120

def create_urtak_question(property, value, question)
  if property == :id
    path = "urtaks/#{value}/questions"
  elsif property == :post_id
    path = "urtaks/post/#{value}/questions"
  elsif property == :permalink
    path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions"
  end

  create_response(fire(:post, path, {:question => question}))
end

#enable_logger(path) ⇒ Object



29
30
31
32
# File 'lib/urtak.rb', line 29

def enable_logger(path)
  require 'logger'
  RestClient.log = @logger = Logger.new(path)
end

#get_account(id) ⇒ Object

ACCOUNTS



39
40
41
# File 'lib/urtak.rb', line 39

def (id)
  create_response(fire(:get, "accounts/#{id}"))
end

#get_publication(key = options[:publication_key]) ⇒ Object

PUBLICATIONS



48
49
50
# File 'lib/urtak.rb', line 48

def get_publication(key = options[:publication_key])
  create_response(fire(:get, "publications/#{key}"))
end

#get_question(id) ⇒ Object



185
186
187
# File 'lib/urtak.rb', line 185

def get_question(id)
  create_response(fire(:get, "questions/#{id}"))
end

#get_urtak(property, value, options = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/urtak.rb', line 65

def get_urtak(property, value, options = {})
  if property == :id
    path = "urtaks/#{value}"
  elsif property == :post_id
    path = "urtaks/post/#{value}"
  elsif property == :permalink
    path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}"
  end
  
  create_response(fire(:get, path, options))
end

#get_urtak_question(property, value, id, options = {}) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/urtak.rb', line 108

def get_urtak_question(property, value, id, options = {})
  if property == :id
    path = "urtaks/#{value}/questions/#{id}"
  elsif property == :post_id
    path = "urtaks/post/#{value}/questions/#{id}"
  elsif property == :permalink
    path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions/#{id}"
  end

  create_response(fire(:get, path, options))
end

#ham_urtak_question(property, value, id) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/urtak.rb', line 168

def ham_urtak_question(property, value, id)
  if property == :id
    path = "urtaks/#{value}/questions/#{id}/ham"
  elsif property == :post_id
    path = "urtaks/post/#{value}/questions/#{id}/ham"
  elsif property == :permalink
    path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions/#{id}/ham"
  end

  create_response(fire(:put, path))
end

#list_questions(options = {}) ⇒ Object

QUESTIONS



181
182
183
# File 'lib/urtak.rb', line 181

def list_questions(options={})
  create_response(fire(:get, "questions", options))
end

#list_urtak_questions(property, value, options = {}) ⇒ Object

URTAK QUESTIONS



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/urtak.rb', line 96

def list_urtak_questions(property, value, options = {})
  if property == :id
    path = "urtaks/#{value}/questions"
  elsif property == :post_id
    path = "urtaks/post/#{value}/questions"
  elsif property == :permalink
    path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions"
  end
  
  create_response(fire(:get, path, options))
end

#list_urtaks(options = {}) ⇒ Object

URTAKS



61
62
63
# File 'lib/urtak.rb', line 61

def list_urtaks(options = {})
  create_response(fire(:get, "urtaks", options))
end

#log(level, message) ⇒ Object



34
35
36
# File 'lib/urtak.rb', line 34

def log(level, message)
  @logger.send(level, message) if @logger
end

#reject_urtak_question(property, value, id) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/urtak.rb', line 144

def reject_urtak_question(property, value, id)
  if property == :id
    path = "urtaks/#{value}/questions/#{id}/reject"
  elsif property == :post_id
    path = "urtaks/post/#{value}/questions/#{id}/reject"
  elsif property == :permalink
    path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions/#{id}/reject"
  end

  create_response(fire(:put, path))
end

#spam_urtak_question(property, value, id) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/urtak.rb', line 156

def spam_urtak_question(property, value, id)
  if property == :id
    path = "urtaks/#{value}/questions/#{id}/spam"
  elsif property == :post_id
    path = "urtaks/post/#{value}/questions/#{id}/spam"
  elsif property == :permalink
    path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions/#{id}/spam"
  end

  create_response(fire(:put, path))
end

#update_publication(key, attributes) ⇒ Object



56
57
58
# File 'lib/urtak.rb', line 56

def update_publication(key, attributes)
  create_response(fire(:put, "publications/#{key}", {:publication => attributes}))
end

#update_urtak(property, attributes) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/urtak.rb', line 81

def update_urtak(property, attributes)
  value = attributes.delete(property)
  
  if property == :id
    path = "urtaks/#{value}"
  elsif property == :post_id
    path = "urtaks/post/#{value}"
  elsif property == :permalink
    path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}"
  end
  
  create_response(fire(:put, path, {:urtak => attributes}))
end