Class: Quandora::Tag

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

Instance Method Summary collapse

Constructor Details

#initialize(conn, api, id) ⇒ Tag

Returns a new instance of Tag.



2
3
4
5
6
# File 'lib/quandora/tag.rb', line 2

def initialize(conn, api, id)
  @conn = conn
  @api = api
  @id = id
end

Instance Method Details

#add(tags) ⇒ Object



75
76
77
78
79
80
# File 'lib/quandora/tag.rb', line 75

def add(tags)
  tags = tags.join(',') if tags.is_a? Array
  resp = @conn.put("/#{@api}/#{@id}/tags/#{tags}") do |req|
    req.headers['Content-Type'] = 'application/json'
  end
end

#create(args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/quandora/tag.rb', line 27

def create(args)
  args = args.stringify_keys

  body = {
    "type": "tag-content",
    "data": {
      "name": args['name'],
      "category": nil,
      "location": nil,
      "url": args['url'],
      "content": args['content']
    }
  }

  resp = @conn.post("#{@api}/#{@id}/tags") do |req|
    req.body = body.to_s
    req.headers['Content-Type'] = 'application/json'
  end
end

#delete(tag_name) ⇒ Object



64
65
66
# File 'lib/quandora/tag.rb', line 64

def delete(tag_name)
  resp = @conn.delete("#{@api}/#{@id}/tags/#{tag_name}")
end

#index(args = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/quandora/tag.rb', line 8

def index(args={})
  args = args.stringify_keys

  query = {}
  query.merge!("q": args["q"]) unless args.fetch('q', nil).nil?
  query.merge!("s": args["s"]) unless args.fetch('s', nil).nil?
  query.merge!("o": args["o"]) unless args.fetch('o', nil).nil?
  query.merge!("l": args["l"]) unless args.fetch('l', nil).nil?

  resp = @conn.get("#{@api}/#{@id}/tags") do |req|
    req.params = query
    req.headers['Content-Type'] = 'application/json'
  end
end

#set(tags) ⇒ Object



68
69
70
71
72
73
# File 'lib/quandora/tag.rb', line 68

def set(tags)
  tags = tags.join(',') if tags.is_a? Array
  resp = @conn.post("/#{@api}/#{@id}/tags/#{tags}") do |req|
    req.headers['Content-Type'] = 'application/json'
  end
end

#show(tag_name, query = nil) ⇒ Object



23
24
25
# File 'lib/quandora/tag.rb', line 23

def show(tag_name, query = nil)
  resp = @conn.get("#{@api}/#{@id}/tags/#{tag_name}/#{query}")
end

#update(args) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/quandora/tag.rb', line 47

def update(args)
  args = args.stringify_keys

  body = {
    "type": "tag-content",
    "data": {
      "content": args["content"],
      "uid": args["uid"]
    }
  }

  resp = @conn.put("#{@api}/#{@id}/tags") do |req|
    req.body = body.to_s
    req.headers['Content-Type'] = 'application/json'
  end
end