Class: MingleParty

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mingle_party.rb

Instance Method Summary collapse

Constructor Details

#initializeMingleParty

Returns a new instance of MingleParty.



8
9
10
11
12
13
# File 'lib/mingle_party.rb', line 8

def initialize
  config = YAML.load(File.read("./config.yml")).first
  @uri = "#{config['host']}/api/v2/projects/#{config['project']}"
  auth = { username: config['username'], password: config['password'] }
  @auth_options = { :basic_auth => auth }
end

Instance Method Details

#change_card_status(number, status) ⇒ Object



20
21
22
23
# File 'lib/mingle_party.rb', line 20

def change_card_status(number, status)
  options = @auth_options.merge({ query: { 'card[properties[][name]' => 'status', 'card[properties][][value]' =>  status } })
  response = self.class.put( "#{@uri}/cards/#{number}.xml", options )
end

#create_card(name, card_type) ⇒ Object



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

def create_card(name, card_type)
  options = @auth_options.merge({ query: {'card[name]' =>  name, 'card[card_type_name]' => card_type } })
  response = self.class.post("#{@uri}/cards.xml", options)
end

#create_user(user) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/mingle_party.rb', line 56

def create_user(user)
  options = @auth_options.merge({ query: { 'user[name]' =>  user[:name], 'user[login]' => user[:login],
                                    'user[email]' => user[:email], 'user[admin]' => user[:admin],
                                    'user[password]' => user[:password],
                                    'user[password_confirmation]' => user[:password_confirmation]} })
  self.class.post("#{@uri}/users.xml", options)
end

#fetch_card(number) ⇒ Object



25
26
27
28
# File 'lib/mingle_party.rb', line 25

def fetch_card(number)
  response = self.class.get( "#{@uri}/cards/#{number}.xml", @auth_options )
  Crack::XML.parse( response.body )
end

#fetch_cardsObject



30
31
32
33
# File 'lib/mingle_party.rb', line 30

def fetch_cards
  response = self.class.get( "#{@uri}/cards.xml", @auth_options )
  Crack::XML.parse( response.body )
end

#fetch_user(id) ⇒ Object



69
70
71
72
# File 'lib/mingle_party.rb', line 69

def fetch_user(id)
  response = self.class.get( "#{@uri}/users/#{id}.xml", @auth_options )
  Crack::XML.parse( response.body )
end

#fetch_usersObject



64
65
66
67
# File 'lib/mingle_party.rb', line 64

def fetch_users
  response = self.class.get( "#{@uri}/users.xml", @auth_options )
  Crack::XML.parse( response.body )
end

#murmur(message, command) ⇒ Object



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

def murmur(message, command)
  options = @auth_options.merge( { query:  { "#{command}".to_sym =>  message } } )
  response = self.class.post( "#{@uri}/murmurs.xml", options )
end

#murmursObject

def delete_card(number)

  self.class.delete( "#{@uri}/cards/#{number}")
end

def delete_cards
  response = fetch_cards
  response['cards'].each{|card| delete_card(card['number'].to_i)}
  response.each {|key, value| puts "#{key}" }
end


46
47
48
49
# File 'lib/mingle_party.rb', line 46

def murmurs
  response = self.class.get( "#{@uri}/murmurs.xml", @auth_options )
  Crack::XML.parse( response.body )["murmurs"]
end