Class: RubyKong::Request::Api::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-kong/request/api.rb

Class Method Summary collapse

Class Method Details

.create ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/ruby-kong/request/api.rb', line 123

def self.create
  url = RubyKong::Utils.endpoint_builder(RubyKong.paths[:api][:create])
  RubyKong::Stub.request(
    :method   => :post,
    :url      => url,
    :request  => {
      :body => {
        :upstream_url => 'https://api.shipit.vn/v1/',
        :request_host => 'api.shipit.vn',
        :name         => 'shipit'
      }
    },
    :response => {
      :status => 201,
      :body   => {
        'upstream_url' => 'https://api.shipit.vn/v1/',
        'id'           => '0faeb3a7-3839-4739-916a-6b139c5b491b',
        'name'         => 'shipit',
        'created_at'   => 1458706997000,
        'request_host' => 'api.shipit.vn'
      }.to_s
    }
  )
end

.delete ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby-kong/request/api.rb', line 35

def self.delete
  # Mock with /apis/shipit path
  path = RubyKong.paths[:api][:delete] + 'shipit'
  url  = RubyKong::Utils.endpoint_builder(path)

  RubyKong::Stub.request(
    :method   => :delete,
    :url      => url,
    :response => {
      :status => 204,
      :body   => ""
    }
  )
end

.list ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/ruby-kong/request/api.rb', line 98

def self.list
  url = RubyKong::Utils.endpoint_builder(RubyKong.paths[:api][:list])

  RubyKong::Stub.request(
    :method   => :get,
    :url      => url,
    :response => {
      :status => 200,
      :body   => {
        "data"  =>
        [
          {
            "upstream_url" => "https://api.shipit.vn/v1/",
            "id"           => "0faeb3a7-3839-4739-916a-6b139c5b491b",
            "name"         => "shipit",
            "created_at"   => 1458706997000,
            "request_host" => "api.shipit.vn"
          }
        ],
        "total" => 1
      }.to_s
    }
  )
end

.retrieve ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ruby-kong/request/api.rb', line 77

def self.retrieve
  # Mock with /apis/shipit path
  path = RubyKong.paths[:api][:retrieve] + 'shipit'
  url = RubyKong::Utils.endpoint_builder(path)

  RubyKong::Stub.request(
    :method   => :get,
    :url      => url,
    :response => {
      :status => 200,
      :body   => {
        "upstream_url" => "https://api.shipit.vn/v1/",
        "id"           => "0faeb3a7-3839-4739-916a-6b139c5b491b",
        "name"         => "shipit",
        "created_at"   => 1458706997000,
        "request_host" => "api.shipit.vn"
      }.to_s
    }
  )
end

.update ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ruby-kong/request/api.rb', line 50

def self.update
  # Mock with /apis/shipit path
  path = RubyKong.paths[:api][:update] + 'shipit'
  url  = RubyKong::Utils.endpoint_builder(path)

  RubyKong::Stub.request(
    :method   => :patch,
    :url      => url,
    :request  => {
      :body => {
        :upstream_url => 'https://api.shipit.vn/v2/',
        :name         => 'shipit'
      }
    },
    :response => {
      :status => 200,
      :body   => {
        'upstream_url' => 'https://api.shipit.vn/v2/',
        'id'           => '0faeb3a7-3839-4739-916a-6b139c5b491b',
        'name'         => 'shipit',
        'created_at'   => 1458706997000,
        'request_host' => 'api.shipit.vn'
      }.to_s
    }
  )
end