Class: Yammdesk::Yammer

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

Constant Summary collapse

CONFIG =
YAML.load_file("config.yml")

Instance Method Summary collapse

Constructor Details

#initializeYammer

Returns a new instance of Yammer.



16
17
18
19
20
# File 'lib/yammdesk/yammer.rb', line 16

def initialize
  @url = CONFIG['yammdesk']['url']
  @token = CONFIG['yammdesk']['token']
@uri = URI(@url)
end

Instance Method Details

#getObject



23
24
25
26
27
28
29
30
# File 'lib/yammdesk/yammer.rb', line 23

def get
  Net::HTTP.start(@uri.host, @uri.port, :use_ssl => @uri.scheme == 'https') do |http|
    response = http.get(@url + "/messages/in_group/872.json?oaccess_token=#{@token}")
    @data = JSON.parse(response.body)
    
    return @data['messages']
  end
end

#get_thread_replies(thread_id) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/yammdesk/yammer.rb', line 32

def get_thread_replies(thread_id)
  Net::HTTP.start(@uri.host, @uri.port, :use_ssl => @uri.scheme == 'https') do |http|
    response = http.get(@url + "/messages/in_thread/#{thread_id}.json?oaccess_token=#{@token}")
    @data = JSON.parse(response.body)
    
  return @data['messages']
  end
end

#get_thread_starter(thread_id) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/yammdesk/yammer.rb', line 41

def get_thread_starter(thread_id)
  url = @url + "/messages/#{thread_id}.json?oaccess_token=#{@token}"
  uri = URI(@url)
  
  Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    response = http.get(url)
    @data = JSON.parse(response.body)
    return @data
  end
end

#is_thread_starter?(id, thread_id) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
# File 'lib/yammdesk/yammer.rb', line 67

def is_thread_starter?(id, thread_id)
  if id == thread_id
    true
  else
    false
  end
end

#reply_exists?(whd_note, yamm_replies) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/yammdesk/yammer.rb', line 52

def reply_exists?(whd_note, yamm_replies)
  if yamm_replies.find { |yamm|
      body = CGI.unescapeHTML(yamm['body']['plain'])
      body = body.gsub('<br/> ', "\n") 
      body = Nokogiri::HTML.parse(body)
      body = body.text
      
      body == whd_note
    }
    return true
  else
    return false
  end
end

#update_thread(thread_id, body) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/yammdesk/yammer.rb', line 75

def update_thread(thread_id, body)
  body = CGI::unescapeHTML(body)
  body = body.gsub('<br/> ', "\n") 
  body = Nokogiri::HTML.parse(body)
  body = body.text
  
  url = @url + "/messages.json&oaccess_token=#{@token}"
  uri = URI(url)
  
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true
  https.verify_mode = OpenSSL::SSL::VERIFY_NONE
  
  request = Net::HTTP::Post.new(uri.request_uri)
  request.set_form_data('replied_to_id' => thread_id, 'body' => body)
  
  response = https.request(request)
  puts "DIDN'T FIND:\n#{body}\n\n".white
end