Class: Zesty::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/zesty/client.rb

Constant Summary collapse

API_URLS =
{
  get_instance: "https://accounts.api.zesty.io/v1/instances/%{instance_zuid}",
  get_models: "https://%{instance_zuid}.api.zesty.io/v1/content/models",
  get_model: "https://%{instance_zuid}.api.zesty.io/v1/content/models/%{model_zuid}",
  get_items: "https://%{instance_zuid}.api.zesty.io/v1/content/models/%{model_zuid}/items",
  get_item: "https://%{instance_zuid}.api.zesty.io/v1/content/models/%{model_zuid}/items/%{item_zuid}",
  update_item: "https://%{instance_zuid}.api.zesty.io/v1/content/models/%{model_zuid}/items/%{item_zuid}",
  get_head_tags: "https://%{instance_zuid}.api.zesty.io/v1/web/headtags",
  create_head_tag: "https://%{instance_zuid}.api.zesty.io/v1/web/headtags",
  delete_head_tag: "https://%{instance_zuid}.api.zesty.io/v1/web/headtags/%{head_tag_zuid}"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, instance_zuid, **options) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
# File 'lib/zesty/client.rb', line 20

def initialize(token, instance_zuid, **options)
  @token = token
  @instance_zuid = instance_zuid
  @options = options
end

Instance Attribute Details

#instance_zuidObject (readonly)

Returns the value of attribute instance_zuid.



18
19
20
# File 'lib/zesty/client.rb', line 18

def instance_zuid
  @instance_zuid
end

Instance Method Details

#create_head_tag(type:, attributes:, sort:, resource_zuid:) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/zesty/client.rb', line 80

def create_head_tag(type:, attributes:, sort:, resource_zuid:)
  Request.post(
    url_for(:create_head_tag),
    params: {
      type: type,
      attributes: attributes,
      sort: sort,
      resource_zuid: resource_zuid
    }.to_camel_case,
    headers: {
      authorization: "Bearer #{@token}"
    }
  )
end

#delete_head_tag(head_tag_zuid) ⇒ Object



95
96
97
# File 'lib/zesty/client.rb', line 95

def delete_head_tag(head_tag_zuid)
  Request.delete(url_for(:delete_head_tag, head_tag_zuid: head_tag_zuid), headers: { authorization: "Bearer #{@token}" })
end

#get_head_tagsObject



76
77
78
# File 'lib/zesty/client.rb', line 76

def get_head_tags
  Request.get(url_for(:get_head_tags), headers: { authorization: "Bearer #{@token}" })
end

#get_instanceObject



26
27
28
# File 'lib/zesty/client.rb', line 26

def get_instance
  Request.get(url_for(:get_instance), headers: { authorization: "Bearer #{@token}" })
end

#get_item(model_zuid, item_zuid) ⇒ Object



42
43
44
# File 'lib/zesty/client.rb', line 42

def get_item(model_zuid, item_zuid)
  Request.get(url_for(:get_item, model_zuid: model_zuid, item_zuid: item_zuid), headers: { authorization: "Bearer #{@token}" })
end

#get_items(model_zuid) ⇒ Object



38
39
40
# File 'lib/zesty/client.rb', line 38

def get_items(model_zuid)
  Request.get(url_for(:get_items, model_zuid: model_zuid), headers: { authorization: "Bearer #{@token}" })
end

#get_model(model_zuid) ⇒ Object



34
35
36
# File 'lib/zesty/client.rb', line 34

def get_model(model_zuid)
  Request.get(url_for(:get_model, model_zuid: model_zuid), headers: { authorization: "Bearer #{@token}" })
end

#get_modelsObject



30
31
32
# File 'lib/zesty/client.rb', line 30

def get_models
  Request.get(url_for(:get_models), headers: { authorization: "Bearer #{@token}" })
end

#publish_item(model_zuid, item_zuid, version_number) ⇒ Object

LEGACY

This will be replaced by ‘update_item(… publish: true)`



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/zesty/client.rb', line 63

def publish_item(model_zuid, item_zuid, version_number)
  Request.post(
    "https://svc.zesty.io/sites-service/#{instance_zuid}/content/items/#{item_zuid}/publish-schedule",
    params: {
      version_num: version_number
    },
    headers: {
      authorization: "Bearer #{@token}",
      'X-Auth': @token
    }
  )
end

#update_item(model_zuid, item_zuid, publish: false, data:, meta:, web: {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/zesty/client.rb', line 46

def update_item(model_zuid, item_zuid, publish: false, data:, meta:, web: {})
  # TODO: include `publish: publish` in `url_for` line once API is announced
  # TODO: add `?publish=%{publish}` to API_URLS `:update_item`
  Request.put(
    url_for(:update_item, model_zuid: model_zuid, item_zuid: item_zuid), # publish: publish),
    params: {
      data: data,
      meta: meta.to_camel_case,
      web: web.to_camel_case
    },
    headers: {
      authorization: "Bearer #{@token}"
    }
  )
end