1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
use error::*; use client::{Client, Method}; mod types; pub use self::types::*; pub struct FulfillmentServiceApi<'a> { client: &'a Client, } impl Client { pub fn fulfillment_service(&self) -> FulfillmentServiceApi { FulfillmentServiceApi { client: self } } } impl<'a> FulfillmentServiceApi<'a> { pub fn get_list( &self, scope: Option<FulfillmentServiceScope>, ) -> Result<Vec<FulfillmentService>> { shopify_wrap! { pub struct Res { fulfillment_services: Vec<FulfillmentService>, } } let res: Res = self.client.request_with_params( Method::Get, "/admin/fulfillment_services.json", &scope.map(|scope| ("scope", scope)), |_| {}, )?; Ok(res.into_inner()) } pub fn create(&self, fulfillment_service: &NewFulfillmentService) -> Result<FulfillmentService> { shopify_wrap! { pub struct Res { fulfillment_service: FulfillmentService, } } let path = "/admin/fulfillment_services.json"; let res: Res = self.client.request(Method::Post, &path, move |b| { b.json(&json!({ "fulfillment_service": fulfillment_service })); })?; Ok(res.into_inner()) } pub fn get(&self, id: i64) -> Result<FulfillmentService> { shopify_wrap! { pub struct Res { fulfillment_service: FulfillmentService, } } let path = format!("/admin/fulfillment_services/{}.json", id); let res: Res = self.client.request(Method::Get, &path, move |_| {})?; Ok(res.into_inner()) } pub fn update( &self, id: i64, fulfillment_service: &UpdatetFulfillmentService, ) -> Result<FulfillmentService> { shopify_wrap! { pub struct Res { fulfillment_service: FulfillmentService, } } let path = format!("/admin/fulfillment_services/{}.json", id); let res: Res = self.client.request(Method::Put, &path, move |b| { b.json(&json!({ "fulfillment_service": fulfillment_service })); })?; Ok(res.into_inner()) } pub fn delete(&self, id: i64) -> Result<()> { use serde_json::Value; shopify_wrap! { pub struct Res { fulfillment_service: FulfillmentService, } } let path = format!("/admin/fulfillment_services/{}.json", id); self.client.request::<Value, _>( Method::Delete, &path, |_| {}, )?; Ok(()) } } #[cfg(test)] mod tests { use super::*; #[test] #[ignore] fn test_fulfillment_service_get_list() { let client = ::client::get_test_client(); let service = client .fulfillment_service() .get_list(Some(FulfillmentServiceScope::All)) .unwrap(); println!("{:#?}", service); } #[test] #[ignore] fn test_fulfillment_service_get_one() { let client = ::client::get_test_client(); let service = client.fulfillment_service().get(191681).unwrap(); println!("{:#?}", service); } #[test] #[ignore] fn test_fulfillment_service_create() { let client = ::client::get_test_client(); let service = client .fulfillment_service() .create(&NewFulfillmentService { name: "S2".to_owned(), callback_url: "https://requestb.in/1gnver61".to_owned(), inventory_management: true, tracking_support: true, requires_shipping_method: true, format: "json".to_owned(), }) .unwrap(); println!("{:#?}", service); } #[test] #[ignore] fn test_fulfillment_service_update() { let client = ::client::get_test_client(); let mut update = UpdatetFulfillmentService::default(); update.name = Some("Ventmere S2".to_owned()); let service = client .fulfillment_service() .update(13008909, &update) .unwrap(); println!("{:#?}", service); } #[test] #[ignore] fn test_fulfillment_service_delete() { let client = ::client::get_test_client(); client .fulfillment_service() .delete(12976141) .optional() .unwrap(); } }