Method: Libring::API#update_attribute

Defined in:
lib/libring/api.rb

#update_attribute(contact_code, name, value, type) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/libring/api.rb', line 70

def update_attribute(contact_code, name, value, type)

  require "net/https"
  require "uri"
  require "json"

  uri = URI.parse("https://api.libring.com/v2/contact/put")

  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true

  req = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})

  req.set_form_data({libring: { "#{contact_code}"=> { "#{name}" => { value: "#{value}", type: "#{type}" } }}.to_json })

  resp = https.request(req)

  if resp.body == "OK"
    { success: true }
  else
    { error: resp.body, success: false }
  end

end