evernote-thrift 1.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/APACHE-LICENSE-2.0.txt +202 -0
  2. data/LICENSE +27 -0
  3. data/NOTICE +5 -0
  4. data/README.md +44 -0
  5. data/evernote-thrift.gemspec +28 -0
  6. data/lib/Evernote/EDAM/errors_constants.rb +14 -0
  7. data/lib/Evernote/EDAM/errors_types.rb +128 -0
  8. data/lib/Evernote/EDAM/limits_constants.rb +252 -0
  9. data/lib/Evernote/EDAM/limits_types.rb +13 -0
  10. data/lib/Evernote/EDAM/note_store.rb +5562 -0
  11. data/lib/Evernote/EDAM/note_store_constants.rb +14 -0
  12. data/lib/Evernote/EDAM/note_store_types.rb +1127 -0
  13. data/lib/Evernote/EDAM/types_constants.rb +20 -0
  14. data/lib/Evernote/EDAM/types_types.rb +1792 -0
  15. data/lib/Evernote/EDAM/user_store.rb +549 -0
  16. data/lib/Evernote/EDAM/user_store_constants.rb +18 -0
  17. data/lib/Evernote/EDAM/user_store_types.rb +417 -0
  18. data/lib/evernote-thrift.rb +39 -0
  19. data/lib/thrift.rb +64 -0
  20. data/lib/thrift/client.rb +62 -0
  21. data/lib/thrift/core_ext.rb +23 -0
  22. data/lib/thrift/core_ext/fixnum.rb +29 -0
  23. data/lib/thrift/exceptions.rb +84 -0
  24. data/lib/thrift/processor.rb +57 -0
  25. data/lib/thrift/protocol/base_protocol.rb +290 -0
  26. data/lib/thrift/protocol/binary_protocol.rb +229 -0
  27. data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
  28. data/lib/thrift/protocol/compact_protocol.rb +426 -0
  29. data/lib/thrift/serializer/deserializer.rb +33 -0
  30. data/lib/thrift/serializer/serializer.rb +34 -0
  31. data/lib/thrift/server/base_server.rb +31 -0
  32. data/lib/thrift/server/mongrel_http_server.rb +58 -0
  33. data/lib/thrift/server/nonblocking_server.rb +305 -0
  34. data/lib/thrift/server/simple_server.rb +43 -0
  35. data/lib/thrift/server/thread_pool_server.rb +75 -0
  36. data/lib/thrift/server/threaded_server.rb +47 -0
  37. data/lib/thrift/struct.rb +237 -0
  38. data/lib/thrift/struct_union.rb +192 -0
  39. data/lib/thrift/thrift_native.rb +24 -0
  40. data/lib/thrift/transport/base_server_transport.rb +37 -0
  41. data/lib/thrift/transport/base_transport.rb +107 -0
  42. data/lib/thrift/transport/buffered_transport.rb +108 -0
  43. data/lib/thrift/transport/framed_transport.rb +116 -0
  44. data/lib/thrift/transport/http_client_transport.rb +53 -0
  45. data/lib/thrift/transport/io_stream_transport.rb +39 -0
  46. data/lib/thrift/transport/memory_buffer_transport.rb +125 -0
  47. data/lib/thrift/transport/server_socket.rb +63 -0
  48. data/lib/thrift/transport/socket.rb +137 -0
  49. data/lib/thrift/transport/unix_server_socket.rb +60 -0
  50. data/lib/thrift/transport/unix_socket.rb +40 -0
  51. data/lib/thrift/types.rb +101 -0
  52. data/lib/thrift/union.rb +179 -0
  53. metadata +99 -0
@@ -0,0 +1,24 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ begin
21
+ require "thrift_native"
22
+ rescue LoadError
23
+ puts "Unable to load thrift_native extension. Defaulting to pure Ruby libraries."
24
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
21
+ module Thrift
22
+ class BaseServerTransport
23
+ def listen
24
+ raise NotImplementedError
25
+ end
26
+
27
+ def accept
28
+ raise NotImplementedError
29
+ end
30
+
31
+ def close; nil; end
32
+
33
+ def closed?
34
+ raise NotImplementedError
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,107 @@
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
21
+ module Thrift
22
+ class TransportException < Exception
23
+ UNKNOWN = 0
24
+ NOT_OPEN = 1
25
+ ALREADY_OPEN = 2
26
+ TIMED_OUT = 3
27
+ END_OF_FILE = 4
28
+
29
+ attr_reader :type
30
+
31
+ def initialize(type=UNKNOWN, message=nil)
32
+ super(message)
33
+ @type = type
34
+ end
35
+ end
36
+
37
+ module TransportUtils
38
+ if RUBY_VERSION >= '1.9'
39
+ def self.get_string_byte(string, index)
40
+ string.getbyte(index)
41
+ end
42
+
43
+ def self.set_string_byte(string, index, byte)
44
+ string.setbyte(index, byte)
45
+ end
46
+ else
47
+ def self.get_string_byte(string, index)
48
+ string[index]
49
+ end
50
+
51
+ def self.set_string_byte(string, index, byte)
52
+ string[index] = byte
53
+ end
54
+ end
55
+ end
56
+
57
+ class BaseTransport
58
+ def open?; end
59
+
60
+ def open; end
61
+
62
+ def close; end
63
+
64
+ def read(sz)
65
+ raise NotImplementedError
66
+ end
67
+
68
+ # Returns an unsigned byte as a Fixnum in the range (0..255).
69
+ def read_byte
70
+ buf = read_all(1)
71
+ return ::Thrift::TransportUtils.get_string_byte(buf, 0)
72
+ end
73
+
74
+ # Reads size bytes and copies them into buffer[0..size].
75
+ def read_into_buffer(buffer, size)
76
+ tmp = read_all(size)
77
+ i = 0
78
+ tmp.each_byte do |byte|
79
+ ::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
80
+ i += 1
81
+ end
82
+ i
83
+ end
84
+
85
+ def read_all(size)
86
+ return '' if size <= 0
87
+ buf = read(size)
88
+ while (buf.length < size)
89
+ chunk = read(size - buf.length)
90
+ buf << chunk
91
+ end
92
+
93
+ buf
94
+ end
95
+
96
+ def write(buf); end
97
+ alias_method :<<, :write
98
+
99
+ def flush; end
100
+ end
101
+
102
+ class BaseTransportFactory
103
+ def get_transport(trans)
104
+ return trans
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,108 @@
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
21
+ module Thrift
22
+ class BufferedTransport < BaseTransport
23
+ DEFAULT_BUFFER = 4096
24
+
25
+ def initialize(transport)
26
+ @transport = transport
27
+ @wbuf = ''
28
+ @rbuf = ''
29
+ @index = 0
30
+ end
31
+
32
+ def open?
33
+ return @transport.open?
34
+ end
35
+
36
+ def open
37
+ @transport.open
38
+ end
39
+
40
+ def close
41
+ flush
42
+ @transport.close
43
+ end
44
+
45
+ def read(sz)
46
+ @index += sz
47
+ ret = @rbuf.slice(@index - sz, sz) || ''
48
+
49
+ if ret.length == 0
50
+ @rbuf = @transport.read([sz, DEFAULT_BUFFER].max)
51
+ @index = sz
52
+ ret = @rbuf.slice(0, sz) || ''
53
+ end
54
+
55
+ ret
56
+ end
57
+
58
+ def read_byte
59
+ # If the read buffer is exhausted, try to read up to DEFAULT_BUFFER more bytes into it.
60
+ if @index >= @rbuf.size
61
+ @rbuf = @transport.read(DEFAULT_BUFFER)
62
+ @index = 0
63
+ end
64
+
65
+ # The read buffer has some data now, read a single byte. Using get_string_byte() avoids
66
+ # allocating a temp string of size 1 unnecessarily.
67
+ @index += 1
68
+ return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1)
69
+ end
70
+
71
+ def read_into_buffer(buffer, size)
72
+ i = 0
73
+ while i < size
74
+ # If the read buffer is exhausted, try to read up to DEFAULT_BUFFER more bytes into it.
75
+ if @index >= @rbuf.size
76
+ @rbuf = @transport.read(DEFAULT_BUFFER)
77
+ @index = 0
78
+ end
79
+
80
+ # The read buffer has some data now, so copy bytes over to the output buffer.
81
+ byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index)
82
+ ::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
83
+ @index += 1
84
+ i += 1
85
+ end
86
+ i
87
+ end
88
+
89
+ def write(buf)
90
+ @wbuf << buf
91
+ end
92
+
93
+ def flush
94
+ if @wbuf != ''
95
+ @transport.write(@wbuf)
96
+ @wbuf = ''
97
+ end
98
+
99
+ @transport.flush
100
+ end
101
+ end
102
+
103
+ class BufferedTransportFactory < BaseTransportFactory
104
+ def get_transport(transport)
105
+ return BufferedTransport.new(transport)
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,116 @@
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
21
+ module Thrift
22
+ class FramedTransport < BaseTransport
23
+ def initialize(transport, read=true, write=true)
24
+ @transport = transport
25
+ @rbuf = ''
26
+ @wbuf = ''
27
+ @read = read
28
+ @write = write
29
+ @index = 0
30
+ end
31
+
32
+ def open?
33
+ @transport.open?
34
+ end
35
+
36
+ def open
37
+ @transport.open
38
+ end
39
+
40
+ def close
41
+ @transport.close
42
+ end
43
+
44
+ def read(sz)
45
+ return @transport.read(sz) unless @read
46
+
47
+ return '' if sz <= 0
48
+
49
+ read_frame if @index >= @rbuf.length
50
+
51
+ @index += sz
52
+ @rbuf.slice(@index - sz, sz) || ''
53
+ end
54
+
55
+ def read_byte
56
+ return @transport.read_byte() unless @read
57
+
58
+ read_frame if @index >= @rbuf.length
59
+
60
+ # The read buffer has some data now, read a single byte. Using get_string_byte() avoids
61
+ # allocating a temp string of size 1 unnecessarily.
62
+ @index += 1
63
+ return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1)
64
+ end
65
+
66
+ def read_into_buffer(buffer, size)
67
+ i = 0
68
+ while i < size
69
+ read_frame if @index >= @rbuf.length
70
+
71
+ # The read buffer has some data now, so copy bytes over to the output buffer.
72
+ byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index)
73
+ ::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
74
+ @index += 1
75
+ i += 1
76
+ end
77
+ i
78
+ end
79
+
80
+
81
+ def write(buf,sz=nil)
82
+ return @transport.write(buf) unless @write
83
+
84
+ @wbuf << (sz ? buf[0...sz] : buf)
85
+ end
86
+
87
+ #
88
+ # Writes the output buffer to the stream in the format of a 4-byte length
89
+ # followed by the actual data.
90
+ #
91
+ def flush
92
+ return @transport.flush unless @write
93
+
94
+ out = [@wbuf.length].pack('N')
95
+ out << @wbuf
96
+ @transport.write(out)
97
+ @transport.flush
98
+ @wbuf = ''
99
+ end
100
+
101
+ private
102
+
103
+ def read_frame
104
+ sz = @transport.read_all(4).unpack('N').first
105
+
106
+ @index = 0
107
+ @rbuf = @transport.read_all(sz)
108
+ end
109
+ end
110
+
111
+ class FramedTransportFactory < BaseTransportFactory
112
+ def get_transport(transport)
113
+ return FramedTransport.new(transport)
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
21
+ require 'net/http'
22
+ require 'net/https'
23
+ require 'uri'
24
+ require 'stringio'
25
+
26
+ module Thrift
27
+ class HTTPClientTransport < BaseTransport
28
+
29
+ def initialize(url, proxy_addr = nil, proxy_port = nil)
30
+ @url = URI url
31
+ @headers = {'Content-Type' => 'application/x-thrift'}
32
+ @outbuf = ""
33
+ @proxy_addr = proxy_addr
34
+ @proxy_port = proxy_port
35
+ end
36
+
37
+ def open?; true end
38
+ def read(sz); @inbuf.read sz end
39
+ def write(buf); @outbuf << buf end
40
+
41
+ def add_headers(headers)
42
+ @headers = @headers.merge(headers)
43
+ end
44
+
45
+ def flush
46
+ http = Net::HTTP.new @url.host, @url.port, @proxy_addr, @proxy_port
47
+ http.use_ssl = @url.scheme == "https"
48
+ resp = http.post(@url.request_uri, @outbuf, @headers)
49
+ @inbuf = StringIO.new resp.body
50
+ @outbuf = ""
51
+ end
52
+ end
53
+ end