Module: Cloudant::QueryBuilder

Included in:
API
Defined in:
lib/cloudant/query_builder.rb

Instance Method Summary collapse

Instance Method Details

#build_attachment_query(args) ⇒ Object

Built the query string for attachments



34
35
36
37
38
39
40
41
# File 'lib/cloudant/query_builder.rb', line 34

def build_attachment_query(args)
  q = ""
  q << "#{database}"
  q << "/#{args[:id]}"
  q << "/#{args[:name]}"
  q << "?rev=#{args[:rev]}" if args[:rev]
  q
end

#build_query_string(opts, type) ⇒ Object

TODO: Add a check to determine if options value is valid for key. ex: true is valid, 6 is not.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cloudant/query_builder.rb', line 5

def build_query_string(opts,type)
  query_str = ""
  fields    = get_fields(type)

  fields.each do |field|
    val = opts[field].to_s

    current = "#{field}=#{val}" if val != ""
    query_str << "&" << current if (query_str != "" && current)
    query_str << "?" << current if (query_str == "" && current)
  end

  query_str
end

#get_fields(type) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cloudant/query_builder.rb', line 20

def get_fields(type)
  case type
    when "view"
      return [:reduce,:include_docs,:descending,:endkey,:endkey_docid,:group,:group_level,:inclusive_end,:key,:keys,:limit,:skip,:stale,:startkey,:startkey_docid]  
    when "all_docs"
      return [:include_docs,:descending,:endkey,:conflicts,:inclusive_end,:key,:limit,:skip,:startkey,:keys]  
    when "changes"
      return [:include_docs,:descending,:feed,:filter,:heartbeat,:conflicts,:limit,:since,:style,:timeout,:doc_ids]  
    when "doc"
      return [:local_seq,:attachments,:att_encoding_info,:atts_since,:conflicts,:deleted_conflicts,:latest,:meta,:open_revs,:rev,:revs,:revs_info]  
  end
end